﻿/*
 * author:yf
 * date:2015/08/05
 * func:NPageLayoutControl MapView
 * modify by ll 2015/11/24
*/
NPageLayoutOptions={
	printServer:'',
	templeteUrl:'',
	title:'',
	viewBox:[],
	svgText:null
};

NCompassOptions={
	compassUrl:'',
	title:'',
	viewBox:[]
};

NPageLayoutClass=NClass.extend({
	_container:null,
	_parent:null,
	_self:null,	 
	_printmap:null,
	_pagerOffsetLeft:null,
	_type:"NPageLayoutClass",
	initialize:function(){
		
	},
	_setLayout:function(parent){
		this._parent = parent;
		if(this._parent && this._container && this._parent._pager){
			if(this instanceof NCompass){
				var mapdiv = document.getElementById("newmapMap");
				this._parent._pager._container.insertBefore(this._container,mapdiv);
			}else{
				this._parent._pager._container.appendChild(this._container);
			}
			NEvent.addListener(this._container,'dblclick',this._setDblclick,this);			
		}	
		this._initCtrl();
	},
	_unsetLayout:function(){
		if(this._parent && this._container && this._parent._pager){
			NEvent.removeListener(this._container,'dblclick',this._setDblclick,this);
			this._parent._pager._container.removeChild(this._container);	
		}	
	},
	_initCtrl:function(){
		
	},
	uuid:function() {
        var s = [];
        var hexDigits = "0123456789abcdef";
        for (var i = 0; i < 36; i++) {
           s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
		s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); 
		s[8] = s[13] = s[18] = s[23] = "";
        var uuid = s.join("");
        return uuid;
    },
	_refesh:function(){
		this._parent._refesh();
		if(this._printmap){this._printmap._handlers["drag"].enable();}
	},
	_ownerrefesh:function(){
		
	},
	_dragZoom:function(svgContainer,svgTarget,rightBottom,right,bottom){
		var that = this;
		var mouseStart = {};
		var divStart = {};
		var rightStart = {};
		var bottomStart = {};
		
		var svg,set,yywidth,yyheight,swidth,sheight;
		var boxWidth,boxHeight;
		if(svgContainer.children.length>0){
			
			yywidth=parseFloat(NUtil.getStyle(svgContainer,'width'));
			yyheight=parseFloat(NUtil.getStyle(svgContainer,'height'));
			
			if(svgContainer.id !="newmapMap"){
				var id=svgContainer.children[0].id;
				svg = Snap("#"+id);
				
				boxWidth = svg.attr("viewBox").width;
				boxHeight = svg.attr("viewBox").height;
				
				var arr=['defs','desc','g','style','metadata'];
				var set = svg.selectAll("*");
				for(var s=0; s<set.length;s++){
					var element = set[s];
					var falg=true;
					for(var m=0;m<arr.length;m++){
						if(element.type == arr[m]){
							falg=false;
							break;
						}
					}
					if(falg){
						var transform = element.transform();
						if(transform){
							var localMatrix = transform.localMatrix;
							yywidth= yywidth/Number(localMatrix.a);
							yyheight= yyheight/Number(localMatrix.d);
							
							boxWidth= boxWidth/Number(localMatrix.a);
							boxHeight= boxHeight/Number(localMatrix.d);
							break;
						}
					}
				}
			}
		}	
		this._yywidth = yywidth;
		this._yyheight = yyheight;
		this._boxWidth = boxWidth;
		this._boxHeight = boxHeight;
		
		function change(xscale,yscale){
			var viewBox = svg.attr("viewBox");
			var ww = that._boxWidth*xscale;
			var hh = that._boxHeight*yscale;
			svg.attr("viewBox",viewBox.x+','+viewBox.y+','+ww+','+hh);
			var arr=['defs','desc','g','style','metadata'];
			set.forEach(function(element,index){
				var falg=true;
				for(var m=0;m<arr.length;m++){
					if(element.type == arr[m]){
						falg=false;
						break;
					}
				}
				if(falg){
					element.transform(new Snap.Matrix().scale(xscale,yscale));
				}
			});	
		}
		
		if(right){
			right.onmousedown = function(ev){
				var oEvent = ev || event;
				mouseStart.x = oEvent.clientX;
				mouseStart.y = oEvent.clientY;
				rightStart.x = right.offsetLeft;
				if (right.setCapture) {
					right.onmousemove = doDrag1;
					right.onmouseup = stopDrag1;
					right.setCapture();
				}
				else {
					document.addEventListener("mousemove", doDrag1, true);
					document.addEventListener("mouseup", stopDrag1, true);
				}
				swidth=parseFloat(NUtil.getStyle(svgContainer,'width'));
				sheight=parseFloat(NUtil.getStyle(svgContainer,'height'));
				
			};
			function doDrag1(ev) {
				var oEvent = ev || event;
				var l = oEvent.clientX - mouseStart.x + rightStart.x;
				var w = l + rightBottom.offsetWidth;
			
				if (w < rightBottom.offsetWidth) {
					w = rightBottom.offsetWidth;	           				
				}
				else if (w > document.documentElement.clientWidth - svgContainer.offsetLeft) {
					w = document.documentElement.clientWidth - svgContainer.offsetLeft - 2;
				}
				
				svgContainer.style.width = w + "px";	
				if(svg){
					var xscale =w/that._yywidth;
					var yscale =sheight/that._yyheight;
					change(xscale,yscale);	
				}
			};
			function stopDrag1(e) {
				e.stopPropagation();
				if (right.releaseCapture) {
					right.onmousemove = null;
					right.onmouseup = null;
					right.releaseCapture();
				}
				else {
					document.removeEventListener("mousemove", doDrag1, true);
					document.removeEventListener("mouseup", stopDrag1, true);
					
					if(that && that._printmap){
						that._printmap._sizeChanged = true;
						that._printmap._resetView();
					}
				}
			};
		}       
		
		if(bottom){
			bottom.onmousedown = function (ev) {			
				var oEvent = ev || event;
				mouseStart.x = oEvent.clientX;
				mouseStart.y = oEvent.clientY;
				bottomStart.y = bottom.offsetTop;
				if (bottom.setCapture) {
					bottom.onmousemove = doDrag2;
					bottom.onmouseup = stopDrag2;
					bottom.setCapture();
				}
				else {
					document.addEventListener("mousemove", doDrag2, true);
					document.addEventListener("mouseup", stopDrag2, true);
				}
				swidth=parseFloat(NUtil.getStyle(svgContainer,'width'));
				sheight=parseFloat(NUtil.getStyle(svgContainer,'height'));
			};
			function doDrag2(ev) {
				var oEvent = ev || event;
				var t = oEvent.clientY - mouseStart.y + bottomStart.y;
				var h = t + rightBottom.offsetHeight;
				if (h < rightBottom.offsetHeight) {
					h = rightBottom.offsetHeight;
				}
				else if (h > document.documentElement.clientHeight - svgContainer.offsetTop) {
					h = document.documentElement.clientHeight - svgContainer.offsetTop - 2;
				}
				
				svgContainer.style.height = h + "px";
				
				if(svg){
					var yscale =h/that._yyheight;
					var xscale =swidth/that._yywidth;
					change(xscale,yscale);
				}
			};
			function stopDrag2() {
				if (bottom.releaseCapture) {
					bottom.onmousemove = null;
					bottom.onmouseup = null;
					bottom.releaseCapture();
				}
				else {
					document.removeEventListener("mousemove", doDrag2, true);
					document.removeEventListener("mouseup", stopDrag2, true);
					
					if(that && that._printmap){
						that._printmap._sizeChanged = true;
						that._printmap._resetView();
					}
				}
			};
		}
	  
		if(rightBottom){
			var a,d;
			rightBottom.onmousedown = function (ev) {	
				var oEvent = ev || event;
				
				mouseStart.x = oEvent.clientX;
				mouseStart.y = oEvent.clientY;
				divStart.x = rightBottom.offsetLeft;
				divStart.y = rightBottom.offsetTop;
				if (rightBottom.setCapture) {
					rightBottom.onmousemove = doDrag;
					rightBottom.onmouseup = stopDrag;
					rightBottom.setCapture();
				}
				else {
					document.addEventListener("mousemove", doDrag, true);
					document.addEventListener("mouseup", stopDrag, true);
				}
				
				swidth=parseFloat(NUtil.getStyle(svgContainer,'width'));
				sheight=parseFloat(NUtil.getStyle(svgContainer,'height'));
				
				var set = svg.selectAll("*");
				for(var s=0; s<set.length;s++){
					var element = set[s];
					var falg=true;
					for(var m=0;m<arr.length;m++){
						if(element.type == arr[m]){
							falg=false;
							break;
						}
					}
					if(falg){
						var transform = element.transform();
						if(transform){
							var localMatrix = transform.localMatrix;
							a=localMatrix.a;
							d=localMatrix.d;
							break;
						}
					}
				}
			};
			function doDrag(ev) {
				var oEvent = ev || event;
				var l = oEvent.clientX - mouseStart.x + divStart.x;
				var t = oEvent.clientY - mouseStart.y + divStart.y;
				
				var w = l + rightBottom.offsetWidth;
				var h = t + rightBottom.offsetHeight;
				if (w < rightBottom.offsetWidth){
					w = rightBottom.offsetWidth;
				}
				else if (w > document.documentElement.clientWidth - svgContainer.offsetLeft) {
					w = document.documentElement.clientWidth - svgContainer.offsetLeft - 2;
				}
				if (h < rightBottom.offsetHeight) {
					h = rightBottom.offsetHeight;
				}
				else if (h > document.documentElement.clientHeight - svgContainer.offsetTop) {
					h = document.documentElement.clientHeight - svgContainer.offsetTop - 2;
				}
				
				svgContainer.style.width = w + "px";
				svgContainer.style.height = h + "px";
				if(svg){
					if((a&&a==1) && d&&d==1){
						var xscale =w/that._yywidth;
						var yscale =h/that._yyheight;
						var scale = xscale>yscale?yscale:xscale;
					
						svgContainer.style.width = scale*that._yywidth + "px";
						svgContainer.style.height = scale*that._yyheight + "px";
						change(scale,scale);
					}else{
						var xscale2 =w/swidth;
						var yscale2 =h/sheight;
						var scale = xscale2>yscale2?yscale2:xscale2;
						
						svgContainer.style.width = scale*swidth + "px";
						svgContainer.style.height = scale*sheight + "px";
						
						var aa = a + scale*swidth/that._yywidth;
						var dd = d + scale*sheight/that._yyheight;
						change(aa,dd);
					}
				}
			};
			function stopDrag(ev) {
				if (rightBottom.releaseCapture) {
					rightBottom.onmousemove = null;
					rightBottom.onmouseup = null;
					rightBottom.releaseCapture();
				}
				else {
					document.removeEventListener("mousemove", doDrag, true);
					document.removeEventListener("mouseup", stopDrag, true);
					if(that && that._printmap){
						that._printmap._sizeChanged = true;
						that._printmap._resetView();
					}
				}
			};
		}
		
		svgTarget.onmousedown = function (ev) {
			var oEvent = ev || event;
			mouseStart.x = oEvent.clientX;
			mouseStart.y = oEvent.clientY;
			divStart.x = svgContainer.offsetLeft;
			divStart.y = svgContainer.offsetTop;
			if (svgTarget.setCapture) {
				svgTarget.onmousemove = doDrag3;
				svgTarget.onmouseup = stopDrag3;
				svgTarget.setCapture();
			}
			else {
				document.addEventListener("mousemove", doDrag3, true);
				document.addEventListener("mouseup", stopDrag3, true);
			}
		};
		function doDrag3(ev) {
			var oEvent = ev || event;
			var l = oEvent.clientX - mouseStart.x + divStart.x;
			var t = oEvent.clientY - mouseStart.y + divStart.y;             
			svgContainer.style.left = l + "px";
			svgContainer.style.top = t + "px";
			svgTarget.style.cursor = 'move';
		};
		function stopDrag3() {
			svgTarget.style.cursor = 'default';
			if (svgTarget.releaseCapture) {
				svgTarget.onmousemove = null;
				svgTarget.onmouseup = null;
				svgTarget.releaseCapture();
			}
			else {
				document.removeEventListener("mousemove", doDrag3, true);
				document.removeEventListener("mouseup", stopDrag3, true);
			}
		}
	},
	_setDblclick:function(e){
		if(e&&e.stopPropagation){
			e.stopPropagation(); 
		}else{
			window.event.cancelBubble = true; 
		}
        this._refesh();
		
		var tarElement;	
		var container = this._container;
		if(e.currentTarget.id=="newmapMap"){
		
			var  flag=false;
			var map = this._printmap;
			var handlers = map._handlers;
			for(var key in handlers){
				if(handlers.hasOwnProperty(key)){
					if(key !="drag" && key !="scrollwheelzoom" && key !="doubleclickzoom" && key !="touchzoom"){
						var handler = handlers[key];
						if(handler._enabled){
							flag=true;
							break;
						}
					}
				}
			}
			if(flag){
				return;
			}
			tarElement = e.currentTarget.childNodes[0];
			this._printmap._handlers["drag"].disable();
		}else{			
			tarElement = e.target.parentNode;
			while(tarElement.tagName == "g"){
				tarElement = tarElement.parentNode;
			}
			if(tarElement.tagName=="svg"){
				container = tarElement.parentNode;
			}else{	return false;}
		}
		if(container==undefined||tarElement==undefined){return false;}
			
		var _curCtrl =  this._parent._curCtrl;	
		if(container.tagName.toLowerCase()=="div"){	
			if(container.id=="newmapMap"){
				 _curCtrl.push(container);	
				 
				 document.getElementById("rightBottom").style.display="block";	
				 document.getElementById("RightUp").style.display="block";
				 document.getElementById("LeftUp").style.display="block";
				 document.getElementById("LeftDown").style.display="block";	
				 document.getElementById("bottom").style.display="block";	
				 document.getElementById("right").style.display="block";
				 document.getElementById("newmapMap").style.border="1px dashed green";	
				 document.getElementById("newmapMap").style.zIndex="3";

				 var rightBottom = document.getElementById("rightBottom");
				 var right = document.getElementById("right");
				 var bottom = document.getElementById("bottom"); 
				
				 this._dragZoom(container,tarElement,rightBottom,right,bottom);
				 
			}else{
				var html ='<div id="_LeftUp" style="cursor:nw-resize;position:absolute;width:3px; border:1px dashed blue;background:green;height:3px;z-index:5;top:-3px; left:-3px;"> </div>';
				html +='<div id="_RightUp" style="top:-3px;right:-3px;position:absolute;width:3px; height:3px;z-index:5;background:green;border:1px dashed blue;"> </div> <div id="_LeftDown" style="bottom:-3px;left:-3px;position:absolute;width:3px; background:green;border:1px dashed blue;height:3px;z-index:5;"> </div>';
				html +='<div id="_right" style="width:3px;height:100%;float:right;position:absolute; right:0;top:0;cursor:e-resize;z-index:18;"></div>';
				html +='<div id="_rightBottom" style="width:6px;height:6px;position:absolute; right:0px;bottom:0px;background-color:#4876FF;cursor:nw-resize;text-align:center;  line-height:15px;float:right;z-index:22;border:1px dashed blue;"></div>';
				html +='<div id="_bottom" style="width:100%;height:3px;position:absolute;left:0; bottom:0;cursor:n-resize;z-index:18;"></div>'; 
				container.innerHTML +=html;	
		
				_curCtrl.push(container);
				container.style.zIndex="5";
				container.style.border="1px dashed green";  
				
				var rightBottom = document.getElementById("_rightBottom");
				var right = document.getElementById("_right");
				var bottom = document.getElementById("_bottom"); 
				var svgtarget = document.getElementById(tarElement.id);//tarElement表示svg 
				this._dragZoom(container,svgtarget,rightBottom,right,bottom);
			}
		}	
		NEvent.addListener(document,'keydown',this._keyDelControl,this);	
		this._parent.currentEditTarget=this;
		if(container.id=="newmapMap"){
			this._colseEditDilag();
		}else{
			this._openEditDilag();
		}
	},	
	_colseEditDilag:function(){
		var pane = document.getElementById('editToolPane');
		if(pane){
			pane.style.display="none";
		}
		
		var colorpane = document.getElementById('colorpane');
		if(colorpane){
			colorpane.remove();
		}
	},
	_openEditDilag:function(){
		var that = this;
		var pane = document.getElementById('editToolPane');
		var content='';
		if(this._type == "NTextControl" || (this._type == "NSvgControl" && this._container.id && this._container.id.split('_')[0]=='text')){
			content = this._getEditTool1();
		}else{
			content = this._getEditTool2();
		}
		
		if(content != ""){
			pane.innerHTML = content;
			pane.style.display="block";
		}
		
		var elementdelbtn = document.getElementById("elementdelbtn");
		if(elementdelbtn){
			NEvent.addListener(elementdelbtn,'click',this._btndelClick,this);
		}
		
		var fontFamily = document.getElementById("fontFamily");
		if(fontFamily){
			fontFamily.onchange=function(ob){
				var uuid=that._uuid;
				var svg = Snap("#svg"+uuid);
				var svgtext = svg.select('text');
				svgtext.attr("font-family",ob.target[ob.target.selectedIndex].value);
			}	
		}
		
		var colorSelect = document.getElementById("colorSelect");
		if(colorSelect){
			NEvent.addListener(colorSelect,'click',this._btncolorSelectClick,this);
		}
		
		var fontWeight = document.getElementById("fontWeight");
		if(fontWeight){
			fontWeight.onclick=function(e){
				var uuid=that._uuid;
				var svg = Snap("#svg"+uuid);
				var svgtext = svg.select('text');
				if(svgtext.attr("font-weight") != "bold" && svgtext.attr("font-weight") != "700"){
					svgtext.attr("font-weight","bold");
				}else{
					svgtext.attr("font-weight","normal");
				}
			}
		}
		
		var fontStyle = document.getElementById("fontStyle");
		if(fontStyle){
			fontStyle.onclick=function(){
				var uuid=that._uuid;
				var svg = Snap("#svg"+uuid);
				var svgtext = svg.select('text');
				if(svgtext.attr("font-style")!="italic"){
					svgtext.attr("font-style","italic");
				}else{
					svgtext.attr("font-style","normal");
				}
			}
		}
		var roateInput = document.getElementById("roateInput");
		if(roateInput){
			NEvent.addListener(roateInput,'blur',this._inputOnblur,this);
			roateInput.onfocus= function(){
				if(this.value==this.defaultValue){
					this.value="";
					this.style.color='#000';
				}
			}
		}
		var svg = Snap("#svg"+this._uuid);
		if(svg && svg.select('text')){
			NEvent.addListener(this._container,'click',this._setclick,this);
			//var svge = document.getElementById("svg"+this._uuid);
			//NEvent.addListener(svge,'click',this._setclick,this);
		}
	},	
	_getEditTool2:function(){
		var str='<table><tr><td><img src="'+PRINT_JS_LIB.PRINT_URL+'images/delete.png" alt="删除" id="elementdelbtn"/></td>';
		//str+='<td>旋转：<input type="text" style="width:50px;color:#999999;" id="roateInput" value="0-360"/></td>';
		str +='</tr></table>';
		return "";
	},
	_getEditTool1:function(){
		var tmpdiv = NUtil.create('div');
		var fontFamily= NUtil.create('select');
		fontFamily.id="fontFamily";
		tmpdiv.appendChild(fontFamily);
		
		var fontFamilyArr=['宋体','微软雅黑','黑体','华文彩云','仿宋','楷体','隶书','幼圆','Agency FB','Arial','Cambria','Microsoft YaHei','Verdana','Geneva','sans-serif','SimSun','Verdana ','Times New Roman','Trebuchet MS','Tahoma','Symbol','Bookman Old Style','LiSu'];
		
		for(var i=0;i<fontFamilyArr.length;i++){
			fontFamily.options.add(new Option(fontFamilyArr[i],fontFamilyArr[i]));
		}	
		var fontFamilystr = tmpdiv.innerHTML;
		
		var str='<table><tr><td><img src="'+PRINT_JS_LIB.PRINT_URL+'images/delete.png" alt="删除" id="elementdelbtn"/></td>';
		//str+='<td>旋转：<input type="text" style="width:50px;color:#999999;" id="roateInput" value="0-360"/></td>';
		str +='<td>字体：'+fontFamilystr+'</td>';
		str +='<td>颜色：<img src="'+PRINT_JS_LIB.PRINT_URL+'images/color.png" style="width:40px;height:18px;" id="colorSelect" alt="颜色" id="elementdelbtn"/></td>';
		//str +='<td>透明度：<input type="range" style="width:90px"></td>';
		str +='<td><input type="button" id="fontWeight" value="B" style="width:30px;height:20px;font-weight: bold;"></td>';
		str +='<td><input type="button" id="fontStyle" value="i" style="width:30px;height:20px;font-style:italic;font-weight:bold;"></td>';
		str +='</tr></table>';
		return str;
	},
	_btncolorSelectClick: function(e){
		var e = e || window.event;

		var fontcolor = document.getElementById('colorpane');
		if(fontcolor){
			fontcolor.style.display="block";
		}else{
			var fontcolor=document.createElement("div");
			fontcolor.style.zIndex = 99;
			fontcolor.style.position = "absolute";
			fontcolor.id="colorpane";
			fontcolor.style.width='270px';
			fontcolor.style.left=e.layerX+270+'px';
			fontcolor.style.top=e.layerY+15+'px';
			var _container = this._parent._container;
			_container.appendChild(fontcolor);
			var ColorHex =new Array('00', '33', '66', '99', 'CC', 'FF');
			var SpColorHex=new Array('FF0000', '00FF00', '0000FF', 'FFFF00', '00FFFF', 'FF00FF');
			var colorTable='';                				 
			for (i = 0; i < 2; i++) {
				for (j = 0; j < 6; j++) {
					colorTable = colorTable + '<tr height=15>'
					if(i == 0){
						colorTable = colorTable + '<td width=15 class="colorTd" style="cursor:pointer;background-color:#' +  ColorHex[j] + ColorHex[j] + ColorHex[j] + '"onclick="javascript:eleColor.style.stroke=this.style.backgroundColor">';	 
					 }else{
						 colorTable = colorTable + '<td width=15 class="colorTd" style="cursor:pointer;background-color:#' + SpColorHex[j] + '">';
					 }
					colorTable = colorTable + '<td width=15 style="background-color:#000000">'
					 for (k = 0; k < 3; k++){
						 for (l = 0; l < 6; l++){
							colorTable = colorTable + '<td width=15 class="colorTd" style="cursor:pointer;background-color:#' + ColorHex[k + i * 3] + ColorHex[l] + ColorHex[j] + '">';
						 }
					}
				 }
			}
			colorTable = '<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" style="cursor:pointer;">'
			+ colorTable + '</table>';
			fontcolor.innerHTML = colorTable;
			
			var that = this;
			var colortds = document.getElementsByClassName("colorTd");
			for(var i=0;i<colortds.length;i++){
				colortds[i].onclick=function(){
					var uuid=that._uuid;
					var svg = Snap("#svg"+uuid);
					var svgtext = svg.select('text');
					svgtext.attr('stroke',this.style.backgroundColor);
					svgtext.attr('fill',this.style.backgroundColor);
					fontcolor.style.display="none";
				}
			}
		}
	},
	_btndelClick: function(e){
		var parent = this._parent;
		parent._removeControl(this);
		this._colseEditDilag();
	},
	_inputOnblur: function(e){
		if(this._parent.currentEditTarget){
			var target = e.currentTarget;
			var value = parseFloat(target.value);
			if(!value){
				return;
			}
			var target = this._parent.currentEditTarget;
			var uuid=target._uuid;
			var idstr = "#svg"+uuid;
			var svg = Snap(idstr);
			
			var grounp = svg.select("g");
			
			var box = grounp.getBBox();
			var x = box.cx;
			var y = box.cy;
			var transform = grounp.transform();
			if(transform){
				grounp.transform(new Snap.Matrix().rotate(value, box.cx, box.cy));
			}
			/*var rot = 0;
			Snap.animate(rot, rot + value, function(value) {
				rot = value;
				grounp.transform(new Snap.Matrix().rotate(value, box.cx, box.cy));
			}, 500);*/
		}	
	},
	_keyDelControl:function(e){
		var currKey=0,e=e||event;
      　currKey=e.keyCode||e.which||e.charCode;
		if(currKey==46){
			var _curCtrl = this._parent._curCtrl;
			_curCtrl[0].parentNode.removeChild(_curCtrl[0]);
			_curCtrl.pop();
			this._parent.currentEditTarget=null;
			
			var pane = document.getElementById('editToolPane');
			pane.innerHTML='';
			pane.style.display="none";
		}
	},
	getType: function(){
		return this._type;
	},
	_setclick:function(e){
		var svg = Snap('#svg'+this._uuid);
		if(svg){ 
			var g = svg.select('g');
			if(g){
				g.remove();
			}
			if(this._interval){
				clearInterval(this._interval);
			}
		}

		var e = e || window.event;
		if(e&&e.stopPropagation){
			e.stopPropagation(); 
		}else{
			window.event.cancelBubble = true; 
		} 
		var container = this._container;
		var height = container.clientHeight;
		
		var offsetX=e.offsetX;
		var offsetY=e.offsetY;
		
		var textbbox = svg.select('text').getBBox();
		var width = parseFloat(textbbox.width);
		var textX=parseFloat(textbbox.x);
		
		var svgtext = document.getElementById(this._uuid);
		var str = $.trim(svgtext.textContent);
		this._textContent = str;
		
		var realLength = 0;  
		var tmp=0;
		for (var i = 0; i < str.length; i++){  
			var charCode = str.charCodeAt(i);  
			if (charCode >= 0 && charCode <= 128)  {
				realLength += 1;  
			}else{
				realLength += 2; 
			}
		}  
		var tmp = (width/realLength).toFixed(6);
		this._unitLen= tmp;
		
		if(offsetX < this._unitLen){
			offsetX = 0;
		}else{
			var realLength2=0;
			for (var i = 0; i < str.length; i++){  
				var len = 0;
				var charCode = str.charCodeAt(i);  
				if (charCode >= 0 && charCode <= 128)  {
					len= 1;  
				}else{
					len= 2; 
				}
				realLength2 +=len;
				offsetX -=len*tmp;
				if(Number(offsetX)<tmp){
					offsetX = realLength2*tmp;
					break;
				}
			}  
		}
		offsetX +=textX;
		var line = svg.paper.line(offsetX,height*0.9,offsetX,height*0.1).attr({
			stroke: "#333",
			strokeWidth: 1
		});
		line.attr("id","line"+this._uuid);
		
		setTimeout(function(){
			line.attr("display","none");
		},500);
		
		this._interval = setInterval(function(){
			line.attr("display","");
			setTimeout(function(){
				line.attr("display","none");
			},500);
		},1000);
		
		var g = svg.paper.g();
		g.add(line);
	
		var text = document.getElementById("inputtext");
		text.onfocus=function(){
			this.textBeingEntered = true;
		};
		text.onblur=function(){
			this.textBeingEntered = false;
		};
		text.focus();
		this._contentFlag=null;
		text.value='';
		
		NEvent.removeListener(text,'keydown',this._keyDel,this);
		NEvent.removeListener(text,'input',this._textchange,this);
		
		NEvent.addListener(text,'keydown',this._keyDel,this);
		NEvent.addListener(text,'input',this._textchange,this);
	},
	_textchange:function(e){
		var target = e.currentTarget;
		var keyName = target.value;
		if(this._delKey){
			if(keyName == ""){
				this._textContent = $.trim(document.getElementById(this._uuid).textContent);
				this._contentFlag = null;
			}
			this._delKey = false;
			return;
		}
		
		var line = Snap('#line'+this._uuid);
		var linePosition = line.getBBox().cx;
		var content = this._textContent;
		if(typeof(this._contentFlag)=="undefined" || this._contentFlag==null){
			var tmppos = 0;
			for(var i=0;i<content.length;i++){
				var len = 0;
				var charCode = content.charCodeAt(i);  
				if (charCode >= 0 && charCode <= 128)  {
					len= 1;  
				}else{
					len= 2; 
				}
				tmppos +=len*this._unitLen;
				if(Math.abs(tmppos-linePosition)<(this._unitLen*0.5)){
					this._contentFlag = i;
					break;
				}
			}
			if(typeof(this._contentFlag)=="undefined" || this._contentFlag==null){
				this._contentFlag = -1;
			}
			this._linePosition= linePosition;
		}
		var str1 = content.substr(0,this._contentFlag+1);
		var str2 = content.substring(this._contentFlag+1,content.length);
			
		var text = document.getElementById(this._uuid);
		var lentp=0;
		var ts = keyName; 
		for(var j=0;j<ts.length;j++){
			var charCode = ts.charCodeAt(j);  
			if (charCode >= 0 && charCode <= 128)   
				lentp += 1;  
			else   
				lentp += 2;  
		}	
		var svg = Snap('#svg'+this._uuid);
		if(svg){ 
			var g = svg.select('g');
			if(g){
				g.remove();
			}
			if(this._interval){
				clearInterval(this._interval);
			}
		}
		text.textContent = str1+keyName+str2;
		var linePosition  =this._linePosition+this._unitLen*lentp; 
	
		var txt =svg.select('text');
		var box = txt.getBBox();
		if(this._type == "NTextControl"){
			this._container.style.width = box.width+4+"px";
		}else{
			this._container.style.width = box.width+"px";
		}
		this._width = parseFloat(this._container.style.width);
		this._height = parseFloat(this._container.style.height);
		svg.attr("viewBox","0,0,"+this._width+","+this._height);
		
		var transform = txt.transform();
		if(transform){
			var localMatrix = transform.localMatrix;
			this._yywidth= this._width/Number(localMatrix.a);//this._yywidth=this._width;
			this._yyheight= this._height/Number(localMatrix.d);//this._yyheight=this._height;
			
			this._boxWidth= this._width/Number(localMatrix.a);//this._boxWidth = this._width;
			this._boxHeight= this._height/Number(localMatrix.d);//this._boxHeight = this._height;
		}

		var height = this._container.clientHeight;
		var line = svg.paper.line(linePosition,height-5,linePosition,5).attr({
			stroke: "#333",
			strokeWidth: 1
		});
		
		line.attr("id","line"+this._uuid);
		var g = svg.paper.g();
		g.add(line);
		
		setTimeout(function(){
			line.attr("display","none");
		},500);
		
		this._interval = setInterval(function(){
			line.attr("display","");
			setTimeout(function(){
				line.attr("display","none");
			},500);
		},1000);
	},
	_keyDel:function(e){
		var currKey=0,e=e||event;
      　currKey=e.keyCode||e.which||e.charCode;
        var keyName = String.fromCharCode(currKey);
		if(currKey == 8){
			this._delKey=true;
	
			var line = Snap('#line'+this._uuid);
			var linePosition = line.getBBox().cx;
			if(currKey == 8 && linePosition <this._unitLen){
				return;
			}
				
			var text = document.getElementById(this._uuid);
			var svg = Snap('#svg'+this._uuid);
			if(svg){ 
				var g = svg.select('g');
				if(g){
					g.remove();
				}
				if(this._interval){
					clearInterval(this._interval);
				}
			}
		
			if(linePosition <this._unitLen){
				return;
			}
			var str = text.textContent;
			var realLength = 0;  
			var len=0;
			var tmppos = 0,tmpstr1='',tmpstr2='';
			for (var i = 0; i < str.length; i++){     
				var charCode = str.charCodeAt(i);  
				if (charCode >= 0 && charCode <= 128) {
					len = 1;
				}else{
					len = 2;	
				}  		
				realLength +=len; 
				tmppos = realLength*this._unitLen;
				var tmp = linePosition-tmppos;
				if(0<=Math.abs(tmp)&& Math.abs(tmp)<this._unitLen){
					tmpstr1 = str.substring(0,i);
					tmpstr2 = str.substring(i+1,str.length);
					linePosition -=this._unitLen*len;
					break;
				}
			}  
			text.textContent = tmpstr1+tmpstr2;
			if(typeof(this._contentFlag)=="undefined" || this._contentFlag==null){
				this._textContent = text.textContent;
				this._delKey = false;
			}
			
			var txt =svg.select('text');
			var box = txt.getBBox();
			this._container.style.width = box.width+"px";
			
			this._width = parseFloat(this._container.style.width);
			this._height = parseFloat(this._container.style.height);
			svg.attr("viewBox","0,0,"+this._width+","+this._height);
			
			var height = this._container.clientHeight;
			var line = svg.paper.line(linePosition,height-5,linePosition,5).attr({
				stroke: "#333",
				strokeWidth: 1
			});
			line.attr("id","line"+this._uuid);
			
			setTimeout(function(){
				line.attr("display","none");
			},500);
			
			this._interval = setInterval(function(){
				line.attr("display","");
				setTimeout(function(){
					line.attr("display","none");
				},500);
			},1000);
			
			var g = svg.paper.g();
			g.add(line);
		}		
	}
});

NPager=NPageLayoutClass.extend({
	_type:"NPager",
	initialize:function(parentCtrl){
		var Pagercss='Pagercss';
		this._container = NUtil.create('div',''); 
		this._container.id="_pager";
		this._container.style.visibility ="hidden";
		this._container.style.position ="absolute";
		this._container.style.backgroundColor = "white";
		
		var tpwidth = parentCtrl.clientWidth*0.08;
		var tpheight = parentCtrl.clientHeight*0.05;
		if(tpheight < 40){
			tpheight = 40;
		}

		this._container.style.top = tpheight+"px";
		this._container.style.left = tpwidth+"px";
		this._container.style.width=parseFloat(parentCtrl.clientWidth-tpwidth*2)+"px";	
        this._container.style.height=parseFloat(parentCtrl.clientHeight-tpheight*2)+"px";
		parentCtrl.appendChild(this._container);
	    return this;
	}
});

NCompass=NPageLayoutClass.extend({
	_type:"NCompass",
	_options:null,
	_container:null,
	_x:null,
	_y:null,
	_width:null,
	_height:null,
	initialize:function(x,y,width,height,options){
		this._x = x;
		this._y = y;
		this._width = width;
		this._height = height;

		this._uuid = this.uuid();
        this._container = NUtil.create("div","");
        this._container.style.position = "absolute";	
		this._container.style.zIndex = "4";
		this._container.id = "compassDiv_"+this._uuid;
		
        if(this._x) this._container.style.left = this._x+"px";
		if(this._y) this._container.style.top = this._y+"px";
		if(this._width) this._container.style.width = this._width+"px";
		if(this._height) this._container.style.height = this._height+"px";
		
		if(options==undefined){
			this._options.compassUrl = "compass.svg";
		}else{
			this._options = options;
			if(this._options.compassUrl=="") this._options.compassUrl = "compass.svg";	
		}	
		 
		var comp='', _this=this;
		Snap.load(this._options.compassUrl,function(f){ 
            var set =f.select("svg");	
			for(var u=0;u<set.node.attributes.length;u++){
				var t= set.node.attributes[u];
				if(t.name=="width"){ t.value="100%";}
				if(t.name=="height"){ t.value="100%";}
			}
		    set.node.setAttribute("id","svg"+this._uuid);
			
			this._container.appendChild(f.node);	 
		},this);
		return this;
	},
	_initCtrl:function(){
	},
	setCompass:function(x,y,width,height,options){
		removeCompass();
		initialize(x,y,width,height,options);
	},
	removeCompass:function(){
		if(this._container) this._container.parentNode.removeChild(this._container);
	}
});

NMapControl=NPageLayoutClass.extend({
	_type:"NMapControl",
	_oldmap:null,
	_printmap:null,	 
	_container:null,
	_x:0,
	_y:0,
	_width:0,
	_height:0,	
	initialize:function(x,y,width,height,oldmap){
		 if(oldmap){ this._oldmap = oldmap;}	
         this._width=width;
		 this._height=height;
		 this._y=y;
		 this._x=x;
		 
		 this._container = NUtil.create('div',''); 
         this._container.style.width=parseFloat(this._width)+"px";
	  	 this._container.style.height=parseFloat(this._height)+"px";
		 this._container.style.top=parseFloat(this._y)+"px";
		 this._container.style.left=parseFloat(this._x)+"px";
		 this._container.style.position="absolute";		
		 this._container.style.zIndex="3";		 
		 this._container.id="newmapMap";
		 
		 var _div=NUtil.create('div','');
		 _div.id="newmapDiv";
		 _div.style.width="100%";
		 _div.style.height="100%";
		 _div.style.position="absolute";	
		 this._container.appendChild(_div);
		 
		var html ='<div id="LeftUp" style="cursor:nw-resize;position:absolute;width:6px; border:1px dashed blue;background:green;display:none;height:6px;z-index:5;top:-3px; left:-3px;"> </div>';
		html +='<div id="RightUp" style="top:-3px;right:-3px;position:absolute;width:6px; height:6px;z-index:5;background:green;border:1px dashed blue;display:none;"> </div> <div id="LeftDown" style="bottom:-3px;left:-3px;position:absolute;width:6px; background:green;border:1px dashed blue;height:6px;z-index:5;display:none;"> </div>';
		html +='<div id="right" style="width:15px;height:100%;float:right;position:absolute; right:0;top:0;cursor:e-resize;z-index:18;display:none;"></div>';
		html +='<div id="rightBottom" style="width:10px;height:10px;position:absolute; right:0px;bottom:0px;background-color:#4876FF;cursor:nw-resize;text-align:center;  line-height:15px;float:right;z-index:22;border:1px dashed blue;display:none;"></div>';
		html +='<div id="bottom" style="width:100%;height:15px;position:absolute;left:0; bottom:0;cursor:n-resize;z-index:18;display:none;"></div>';
		this._container.innerHTML += html;
		return this;
	},
	_initCtrl:function(){
		if(this._oldmap)
		{
			if(this._printmap == null){
				this._printmap=new NMap(this._container.childNodes[0].id);
			}
			var oldMpLyrs = this._oldmap.getLayers();
		    var newlayer;
		    for(var lys=0; lys<oldMpLyrs.length; lys++){
				if(oldMpLyrs[lys].visible){
					this.addLayer(oldMpLyrs[lys]);
				}
			}
			//this._printmap.zoomToExtent(this._oldmap.getExtent());
			this._printmap.zoomToScale(this._oldmap.getScale(),this._oldmap.getCenter());
			
			var overLays = this._oldmap._overlays;
			for(var key in overLays){
				if(overLays.hasOwnProperty(key)){
					var overlay = this._oldmap.getOverlay(key);
					if(overlay){
						var marker;
						if(overlay instanceof NSpriteMarker){
							marker = new NSpriteMarker(overlay.getPosition(),overlay.options);
							this._printmap.addOverlays(marker);
						}else if(overlay instanceof NMarker){
							marker = new NMarker(overlay.getPosition(), overlay.options);
							this._printmap.addOverlays(marker);
						}else if(overlay instanceof NRichMarker){
							marker = new NRichMarker(overlay.getPosition(),overlay.getContent(),overlay.options);
							this._printmap.addOverlays(marker);
						}else if(overlay instanceof NLabel){
							if(overlay.options.isDepend){
								continue;
							}
							marker = new NLabel(overlay.getPosition(),overlay.options);
							this._printmap.addOverlays(marker);
							if(overlay.options.hasOwnProperty('visible')){
								marker.setVisible(overlay.options.visible);
							}
							
							var className = overlay._element.className;
							var arr = className.split(' ');
							for(var i=0;i<arr.length;i++){
								var reg = /^\s*|\s*$/g;
								var clss = arr[i].replace(reg, "")
								if(clss =="newmap-label" || clss =="newmap-clickable" || clss==""){
									continue;
								}
								marker.addClass(clss);
							}
						}
						else{
							var tmpoverlay;
							var type = overlay._type;
							var options = overlay.options;
							switch(type)
							{
								case "NPoint":
									tmpoverlay = new NPoint(overlay._latlng,options);
									break;
								case "NPolyline": 
									tmpoverlay = new NPolyline(overlay._points,options);
									break;
								case "NPolygon": 
									tmpoverlay = new NPolygon(overlay._points,options);
									break;
								case "NCircle": 
									tmpoverlay = new NCircle(overlay._latlng,overlay._mRadius,options);
									break;
								case "NRect": 
									tmpoverlay = new NRect(overlay.getBounds(),options);
									break;	
								case "NSector": 
									tmpoverlay = new NSector(overlay._slatlng,overlay._passpoint,overlay._edegree,overlay._draw,options);
									break;		
								case "NMultiPoint": 
									tmpoverlay = new NMultiPoint(overlay._points,options);
									break;	
								case "NMultiPolyline": 
									var points = overlay._points;
									var polylineArr=[];
									for(var i=0;i<points.length;i++){
										var polyline = new NPolyline(points[i]);
										polylineArr.push(polyline);
									}
									tmpoverlay = new NMultiPolyline(polylineArr,options);
									break;	
								case "NMultiPolygon":
									var points = overlay._points;
									var polygonArr=[];
									for(var i=0;i<points.length;i++){
										var polygon = new NPolygon(points[i]);
										polygonArr.push(polygon);
									}							
									tmpoverlay = new NMultiPolygon(polygonArr,options);
									break;	
								default:
							}
							this._printmap.addOverlays(tmpoverlay);
							if(overlay.setVisible){
								tmpoverlay.setVisible(overlay.getVisible());
							}
						}
					}	
				}	
			}	
			this._printmap.setMode("dragzoom");
		}
	},
	setMap:function(map){
		if(map){
			this._oldmap = map;
			this.removeLayers();
			this._initCtrl();
		}
	},
	removeLayer:function(layer){
		if(layer) this._printmap.removeLayer(layer);
	},
	removeLayers:function(){
		if(this._printmap){
			var layr = this.getLayers();
			for(var i=0;i<layr.length;i++){
				this.removeLayer(layr[i]);
			}
		}
	},
	addLayer:function(layer){
		if(layer && this._printmap){
			var typestr = layer.getLayerType();
			var newLayer;
			if(typestr == "NMapServerLayer" || typestr=="NWMSLayer" ){
				var lrOptions={
					isBasicLayer:layer.isBasicLayer,
					units: layer.units,
					projection: layer.projection.srsCode,	
					maxExtent:new NBounds(layer.maxExtent.minX,
									   layer.maxExtent.minY,        
									   layer.maxExtent.maxX,      
									   layer.maxExtent.maxY)
				}
				var params = layer._params;
				if(typestr == "NMapServerLayer")
					newLayer=new NMapServerLayer(layer.name,layer.url,lrOptions,params);
				else{
					newLayer=new NWMSLayer(layer.name,layer.url,lrOptions,params);	
				}
					
			}else if(typestr=="NWMTSLayer" || typestr=="NMultiLayer"){
				newLayer=new NWMTSLayer(layer.name,layer.url,layer.options);
			}else if(typestr=="NTileLayer"){
				newLayer=new NTileLayer(layer.name,layer.url,layer.options);
			}
			this._printmap.addLayer(newLayer);
		}
	},
	getLayers:function(){
		return this._printmap.getLayers();
	},
	setX:function(x){
		this._x=x;
		this._container.style["left"]=parseFloat(this._x)+"px";
	},
	setY:function(y){
		this._y=y;
		this._container.style["top"]=parseFloat(this._y)+"px";
	},
	setWidth:function(width){
		this._width=width;
		this._container.style["width"]=parseFloat(this._width)+"px";
	},
	setHeight:function(height){
		this._height=height;
		this._container.style["height"]=parseFloat(this._height)+"px";
	}
});

NSvgControl=NPageLayoutClass.extend({
	_type:"NSvgControl",
	_options:null,
	_x:null,
	_y:null,
	_width:null,
	_height:null,
	_uuid:null,
	initialize:function(x,y,width,height,options){
		this._x=x;
		this._y=y;
		this._width=width;
		this._height=height;
		this._options = options;
		this._container = NUtil.create('div',''); 
		this._container.name="model";
		
		this._uuid = this.uuid();
		if(this._options.id){
			this._container.id=this._options.id+"_"+this._uuid;
		}
		if(this._width&&this._height){
			this._container.style.width = this._width+"px";
			this._container.style.height= this._height+"px";
			this._container.style.position = "absolute";
			this._container.style.zIndex='2';
			this._container.style.top  = this._y + "px";
			this._container.style.left = this._x + "px";
		}
		var _svg =document.createElementNS("http://www.w3.org/2000/svg","svg");
		var _viewBox ='0,0,'+this._width+','+this._height;
		if(this._options)
		{
			if(this._options["svgNode"]){
				_svg = this._options["svgNode"];
			}
			_svg.setAttribute("id","svg"+this._uuid);
			_svg.setAttribute("width","100%");
			_svg.setAttribute("height","100%");
			var svgText = this._options["svgText"];
			if(svgText){
				_svg.appendChild(svgText);
			}
			var viewBox =  this._options["viewBox"];
			if(viewBox) _viewBox =  viewBox;				
		}
		if(typeof(_viewBox) != 'string'){
			var _viewBoxstr='';
			for(var i=0,len=_viewBox.length;i<len;i++){
			  _viewBoxstr +=_viewBox[i]+',';
			}
			_viewBox = _viewBoxstr.substring(0,_viewBoxstr.length-1);
		}
		_svg.setAttribute("viewBox",_viewBox);	
		var node = 	_svg.children?_svg.children[0]:_svg.childNodes[0];
		if(node && (node.nodeName=="g" || node.nodeName=="text")){
			node.setAttribute("id",this._uuid);
		}
		this._container.appendChild(_svg);
		return this;
	},
	_ownerrefesh:function(){
		var svg = Snap('#svg'+this._uuid);
		if(svg && svg.select('text')){
			NEvent.removeListener(this._container,'click',this._setclick,this);
			var svg = Snap('#svg'+this._uuid);
			if(svg){ 
				var g = svg.select('g');
				if(g){
					g.remove();
				}
				if(this._interval){
					clearInterval(this._interval);
				}
			}
		}
	},
	_initCtrl:function(){
	     
	}
});

NTextControl = NPageLayoutClass.extend({
	_type:"NTextControl",
	initialize:function(x,y,width,height,options){
		this._options=options;
		this._x=x;
		this._y=y;
		
		this._container = NUtil.create('div',''); 
		this._container.className="textDiv";
		this._container.style.top = y+"px";
		this._container.style.left = x+"px";
		this._container.style.zIndex = "4";
		this._container.style.position = "absolute";
		
		var _svg = Snap();
		this._uuid = this.uuid();
		_svg.attr("id","svg"+this._uuid);
		_svg.attr("width","100%");
		_svg.attr("height","100%");
		
		var txt = _svg.paper.text(0, 0, "文本");
		txt.attr('id',this._uuid);
		txt.attr("font-size",24);
		txt.attr("font-family","宋体");
		txt.attr("stroke-width","0");
		
		var box = txt.getBBox();
		txt.attr("x",box.width/2-box.cx+2);
		txt.attr("y",box.height/2-box.cy+1);
		
		this._width = box.width;
		this._height = box.height;
		
		this._container.style.width = this._width+8+"px";
		this._container.style.height = this._height+2+"px";
		
		var ww = this._width+4;
		var hh = this._height+2;
		_svg.attr("viewBox","0,0,"+ww+","+hh);
		
		this._container.appendChild(_svg.node);
		return this;
	},
	_initCtrl:function(){
	},
	_ownerrefesh:function(){
		NEvent.removeListener(this._container,'click',this._setclick,this);
		var svg = Snap('#svg'+this._uuid);
		if(svg){ 
			var g = svg.select('g');
			if(g){
				g.remove();
			}
			if(this._interval){
				clearInterval(this._interval);
			}
		}
	}
});

NPageLayout = NClass.extend({
	includes: NEWMAP_JS_LIB.PublicParts.Events,
	_container:null, 
	_map:NMap, 
	options:NPageLayoutOptions,
	_ctrlArr:null, 
	_pager:null, 
	
	 /**
	 * @property 
     * @description 用于设置代理地址，解决跨域问题
     * @return {String}
	 * @default null
     */
    proxy: null,
	
	initialize:function(containerID,map,options){
		if(!options.hasOwnProperty("templeteUrl") || !ptions["templeteUrl"] || ptions["templeteUrl"]==""){
			options["templeteUrl"]=PRINT_JS_LIB.PRINT_URL+"/templet/Template1.svg";
		}
		
		NUtil.setOptions(this, options);
		if(!this.options.printServer || this.options.printServer=='' ){
			 throw new Error("No definition of print services. ");
		}

		this._ctrlArr = [];
		this._map = map;
		
		this._container = NUtil.get(containerID);
         if (this._container._newmapPrint_used_tag) {
            // throw new Error("printMap container is already initialized.");
         }
        this._container._newmapPrint_used_tag = true;
		var container = this._container;
        container.innerHTML = '';
		container.style.display = "";
		
		NUtil.addClass(container, 'printmapcss');
		if (NUtil.Browser.touch) {
            NUtil.addClass(container, 'newmap-touch');
        }
		
		var position = NUtil.getStyle(container, 'position');
        if (position !== 'absolute' && position !== 'relative' && position !== 'fixed'){
            container.style.position = 'relative';
        }
		
		var panes = this._panes = {};
		this._mapPane = panes.mapPane = NUtil.create('div', 'printmap-map-pane', this._container);
		this._mapSpinnerPane = panes.mapPane = NUtil.create('div', 'printmap-spinner-pane', this._container);
		this._mapSpinnerPane.id="spinnerPane";
		this._mapSpinnerPane.style.display="none";
		
        this._menuPane = panes.menuPane = NUtil.create('div', 'printmap-menu-pane', this._container);
		this._mapPane.style.width=(container.clientWidth-this._menuPane.clientWidth)+"px";
		this._mapSpinnerPane.style.width=(container.clientWidth-this._menuPane.clientWidth)+"px";
		
		NEvent.addListener(this._mapPane,'dblclick',this._removeDbclick,this);	
		
		var input = NUtil.create('input', 'printmap-input-text', this._container);
		input.autocomplete="off";
		input.size="35";
		input.id="inputtext";
		
		 this._pager = new NPager(this._mapPane);
		 if(options == undefined){
			 this.options.templeteUrl="moRen.svg";
		 }else{
			 this.options=options;
			 if(options.templeteUrl == ""){this.options.templeteUrl="moRen.svg";}
		 }
		 this._parseModel();
		 this._getInfoSuccess();
	},
	_removeDbclick:function(){
		this._refesh();
	},
	_refesh:function(){
		var nameBrr=["LeftUp","RightUp","LeftDown","rightBottom"];
		for(var i=0;i<nameBrr.length;i++){
			var node=document.getElementById(nameBrr[i]);
			if(node){node.style.display="none";}
		}

		var nameArr1=["_LeftUp","_RightUp","_LeftDown","_right","_rightBottom","_bottom"];
		for(var i=0;i<nameArr1.length;i++){
			var node=document.getElementById(nameArr1[i]);
			if(node){node.parentNode.removeChild(node);}
		} 
		
		var _curCtrl =  this._curCtrl;
        if(_curCtrl){
			if(_curCtrl.length!=0){				
				var eleContainer = _curCtrl[0];
				eleContainer.style.border='';
				if(eleContainer.id=="newmapMap"){
					document.getElementById(eleContainer.children[0].id).onmousedown=null;
					eleContainer.style.zIndex="3";
			    }else{
					var tarElement;
					var tarElementArr = eleContainer.getElementsByTagName("svg");
					if(tarElementArr && tarElementArr.length>0){
						tarElement=tarElementArr[0];
					}
					if(tarElement){
						while(tarElement.tagName == "g"){
							tarElement = tarElement.parentNode;
						}
						tarElement.onmousedown=null;
					}
					eleContainer.style.zIndex="4";
				}
				_curCtrl.pop();
		   }			
		}	
		if(this.currentEditTarget){
			var that = this.currentEditTarget;
			that._ownerrefesh();
		}
		
		var pane = document.getElementById('editToolPane');
		pane.innerHTML='';
		pane.style.display="none";
	},
	_getInfoSuccess:function(){
		var paper = document.getElementById("_pager");
		var width = parseInt(paper.style.width);
		var height = parseInt(paper.style.height);
		
		var widthcm = parseFloat(width/96*25.4).toFixed(2);
		var heightcm = parseFloat(height/96*25.4).toFixed(2);
		var that = this;
		var doc ='';
		var templateStr='';
		$.ajax({
		    url: "/AMD/libs/mapapi/print/config.xml",
			dataType: 'xml',
			type: 'GET',
			timeout: 2000,
			async : false,
			error: function(xml){
				alert("加载XML 文件出错！");
			},
			success: function(xml){
				$(xml).find("option").each(function()
				{
					doc +='{';
					doc +='"value":"'+$(this).find("value").text()+'",';
					doc +='"name":"'+$(this).find("name").text()+'",';
					doc +='"imgUrl":"'+$(this).find("imgUrl").text()+'",';
					doc +='"svgUrl":"'+$(this).find("svgUrl").text()+'",';
					
					var files = $(this).find("files").text();
					if(files){
						var arr = files.split(',');
						var newvalue='';
						for(var m=0,len=arr.length;m<len;m++){
							newvalue +='"'+arr[m]+'",'
						}
						
						newvalue = newvalue.substring(0,newvalue.length-1);
						doc +='"files":['+newvalue+']';
					}
					doc +='},';
				});
				if(doc!=''){
					doc = doc.substring(0,doc.length-1);
				}
				
				$(xml).find("template").each(function(j)
				{
					templateStr +='{';
					templateStr +='"value":"'+$(this).find("value").text()+'",';
					templateStr +='"imgUrl":"'+$(this).find("imgUrl").text()+'",';
					templateStr +='"svgUrl":"'+$(this).find("svgUrl").text()+'",';
					templateStr +='},'
				});
				if(templateStr!=''){
					templateStr = templateStr.substring(0,templateStr.length-1);
					templateStr ='{data:['+templateStr+']}';
				}
			}
		});
		
		if(doc==''){
			doc = '{data:[{value:"指北针",name:"compass",imgUrl:"svg/svgimg/compass",svgUrl:"svg/svgfile/compass",files:["compass_0"]},{value:"文本",name:"text",imgUrl:"svg/svgimg/text",svgUrl:"svg/svgfile/text",files:["text_0"]}]}';
		}else{
			doc ='{data:['+doc+']}';
		}
		var obj = eval('(' + doc + ')');
		var data = obj.data;
		
		var str='<div class="tc_top">参数设置';
		str+='<p><a href="#" id="modelBtn" onmouseover="MM_swapImage(\'Image1\',\'\',\''+PRINT_JS_LIB.PRINT_URL+'img/right1.png\',1)" onmouseout="MM_swapImgRestore()">模板<img src="'+PRINT_JS_LIB.PRINT_URL+'img/right.png" alt="right" align="absmiddle" id="Image1"></a></p>';
		str+='</div>';
		str+='<div class="tc_left" id="tc_left_pane">';
		str+='<div class="title">图饰设置</div>';
		str+='<div class="tl">';
		str+='<dd>图 饰';
		str+='<select name="图饰" id="legendsSel">';
		for(var i=0;i<data.length;i++){
			var nodeObj = data[i];
			str+='<option value ="'+nodeObj.name+'">'+nodeObj.value+'</option>';
		}
		str+='</select>';
		str+='</dd>';
		str+='<div id="divdl">';
		for(var i=0;i<data.length;i++){
			var nodeObj = data[i];
			var imgUrl = nodeObj.imgUrl;
			var svgUrl = nodeObj.svgUrl;
			var files = nodeObj.files;

			var num=8;
			if(nodeObj.name=='geometry'){
				num=15;
			}
			var len = Math.ceil(files.length/num);
			for(var j=0;j<len;j++){
				if(i==0 && j==0){
					str+='<dl id="dl_'+j+'_'+nodeObj.name+'" name='+nodeObj.name+'>';
				}else{
					str+='<dl id="dl_'+j+'_'+nodeObj.name+'" style="display:none" name='+nodeObj.name+'>';
				}
				for(var n=0;n<num;n++){
					var index = num*j+n;
					if(index<files.length){
						str+='<a href="#"><img id="'+files[index]+'" src="'+PRINT_JS_LIB.PRINT_URL+imgUrl+'/'+files[index]+'.png" name="geometrybtn" alt="'+PRINT_JS_LIB.PRINT_URL+svgUrl+'/'+files[index]+'"></a>';
					}
				}
				str+='</dl>';
			}
		}
		str+='</div>';
		str+='<div id="pagebefafter" style="display:none">';
		str+='<img id="pagebef" src="'+PRINT_JS_LIB.PRINT_URL+'/images/geometry/pagebef.png" style="float:left" />';
		str+='<img id="pageafter" src="'+PRINT_JS_LIB.PRINT_URL+'/images/geometry/pageafter.png" style="float:right" />';
		str+='</div>';
		
		str+='</div>';

		str+='<div class="title">页面设置</div>';
		str+='<div class="tl">';
		str+='<dd>纸张大小<select id="paperSelect">';
		str+='<option value ="自定义">自定义</option><option value ="A0">A0</option><option value="A1">A1</option><option value="A2">A2</option><option value ="A3">A3</option><option value ="A4">A4</option>';
		str+='</select></dd>';
		str+='<dt>宽高等比例<input id="widthHeightScale" name="" type="checkbox" checked></dt>';
		str+='<dd>图片宽度<input id="widthtext" name="" type="text" value="'+widthcm+'"><span style="margin-left:3px">mm</span></dd>';
		str+='<dd>图片高度<input id="heighttext" name="" type="text" value="'+heightcm+'"><span style="margin-left:3px">mm</span></dd>';
		str+='<dd>分  辨  率<select id="dpiSelect" style="margin-left:25px;">';
		str+='<option value ="96">96</option><option value ="72">72</option>';
		str+='</select></dd>';
		str+='<dd>图片格式<select id="formattext" name="格式"><option>png</option></select></dd>';
		str+='<dt>是否异步请求<input name="asynradiobtn" type="radio" value="yes" checked>&nbsp;&nbsp;是<input name="asynradiobtn" type="radio" value="no">&nbsp;&nbsp;否</dt>';
		str+='<li style="margin-top:20px;"><input name="" id="submitbtn" type="button" value="提交" onmouseover="this.style.cursor=\'pointer\';" style="margin-left:60px;"><input name="" id="closebtn" type="button" value="关闭" onmouseover="this.style.cursor=\'pointer\';"></li>';
		str+='</div>';
		str+='</div>';
		str+='<div class="gb"><a href="#" id="a1" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image10\',\'\',\''+PRINT_JS_LIB.PRINT_URL+'img/gb.png\',1)"><img src="'+PRINT_JS_LIB.PRINT_URL+'img/gb2.png" id="closeimg" name="Image10" border="0" id="Image10"></a></div>';
		str+='<div class="gb2" id="editToolPane" style="display:none"></div>';//编辑浮动框
		str+='<div class="gb3" id="modelPane" style="display:none"></div>';//编辑浮动框
		this._menuPane.innerHTML=str;
		
		var modelPane = document.getElementById('modelPane');
		var obj2 = eval('(' + templateStr + ')');
		var templates = obj2.data;
		for(var k=0,tlen=templates.length;k<tlen;k++){
			var tmpa = NUtil.create('a');
			tmpa.href='#';
			var tmpdiv = NUtil.create('img',"modeldivBtn",tmpa);
			tmpdiv.src=PRINT_JS_LIB.PRINT_URL+'templet/'+templates[k]['imgUrl']+'.png';
			tmpdiv.id=templates[k]['svgUrl'];
			tmpdiv.title=templates[k]['value'];
			NEvent.addListener(tmpdiv,'click',this._selectModel,this);
			modelPane.appendChild(tmpa);
		}
		NEvent.addListener(modelPane,'mouseout',this._btnModelOut,this);
		NEvent.addListener(modelPane,'mouseover',this._btnModelIn,this);
		
		var modelBtn = document.getElementById("modelBtn");
		//NEvent.addListener(modelBtn,'mouseover',this._btnModelIn,this);
		
		var paperSelect = document.getElementById("paperSelect");
		NEvent.addListener(paperSelect,'change',this._paperSelectChange,this);
		
		var widthtext = document.getElementById("widthtext");
		NEvent.addListener(widthtext,'change',this._whtextChange,this);
		
		var heighttext = document.getElementById("heighttext");
		NEvent.addListener(heighttext,'change',this._whtextChange,this);
		
		var legendsSel = document.getElementById("legendsSel");
		NEvent.addListener(legendsSel,'change',this._legendsSelChange,this);
		
		var submitbtn = document.getElementById("submitbtn");
		NEvent.addListener(submitbtn,'click',this._btnSubmitClick,this);
		
		var closebtn = document.getElementById("closebtn");
		NEvent.addListener(closebtn,'click',this._btnCloseClick,this);
		
		var closebtn2 = document.getElementById("closeimg");
		NEvent.addListener(closebtn2,'click',this._btnCloseClick,this);
		
		var legendImgs = document.getElementsByName("legendImg");
		for(var i=legendImgs.length-1; i>-1;i--){
			NEvent.addListener(legendImgs[i],'mouseover',this._legendMouseOver,this);
			NEvent.addListener(legendImgs[i],'mouseout',this._legendMouseOut,this);
		}
		
		var geometrybtn = document.getElementsByName("geometrybtn");
		for(var i=0;i<geometrybtn.length;i++){
			NEvent.addListener(geometrybtn[i],'click',this._drawControl,this);
		}
		
		var pagebef = document.getElementById("pagebef");
		NEvent.addListener(pagebef,'click',this._pageChange,this);
		
		var pageafter = document.getElementById("pageafter");
		NEvent.addListener(pageafter,'click',this._pageChange,this);
		
		if(data.length>0 && data[0].value){
			var dlArr2 = document.getElementsByName(data[0].value);
			var pageDiv = document.getElementById("pagebefafter");
			if(dlArr2.length>1){
				pageDiv.style.display="";
			}
		}
	},
	_pageChange:function(e){
		var target = e.currentTarget;
		
		var legendSel = document.getElementById("legendsSel");
		var value = legendSel.options[legendSel.options.selectedIndex].value;
		
		var divdl = document.getElementById("divdl");
		var dlArr = document.getElementsByName(value);
		
		var flagIndex=-1;
		var len = 0;
		var index = -1;
		if(target.id=="pageafter"){
			index=1;
			len=dlArr.length-1;
		}
		var flag = false;
		for(var i=0;i<dlArr.length;i++){
			if(dlArr[i].style.display==""){
				if(i==len){
					flag=true;
					break;
					return;
				}else{
					dlArr[i].style.display="none";
					flagIndex = i+index;
				}
			}
		}
		if(flagIndex !=-1){
			dlArr[flagIndex].style.display="";
		}
		if(len == flagIndex){
			var pageafter = document.getElementById("pageafter");
			var pagebef = document.getElementById("pagebef");
			
			if(target.id=="pageafter"){
				pageafter.src=PRINT_JS_LIB.PRINT_URL+'/images/geometry/pageafter2.png';
				pagebef.src=PRINT_JS_LIB.PRINT_URL+'/images/geometry/pagebef.png';
			}else{
				pagebef.src=PRINT_JS_LIB.PRINT_URL+'/images/geometry/pagebef2.png';
				pageafter.src=PRINT_JS_LIB.PRINT_URL+'/images/geometry/pageafter.png';
			}
		}
	},
	_drawFun:function(e){
		var mapControl = this.getControlByType("NMapControl");
		var map = mapControl._printmap;
		map.off('click',this._drawFun,this);
		var offsetX = mapControl._container.offsetLeft;
		var offsetY = mapControl._container.offsetTop;
		
		if(this._currentTag){
			var abspixel = e.absPixel;
			var pixel = e.pixel;
			var x = pixel.x+offsetX/2;
			var y = pixel.y+offsetY/2;
			
			var control;
			var url = this._currentTag;
			
			var legendSel = document.getElementById("legendsSel");
			var value = legendSel.options[legendSel.options.selectedIndex].value;
			if(value =="compass"){
				Snap.load(url+".svg",function(f){ 
					var set =f.select("svg");	
					var width = parseFloat(set.attr('width'));
					var height = parseFloat(set.attr('height'));
					var viewBox = set.attr('viewBox');
					var boxWidth=width;
					var boxheight=height;
					if(viewBox){
						boxWidth = viewBox.width;
						boxheight = viewBox.height;
					}
					var scale = 60/width;
					height = scale*height;	
					var svgHTML = set.innerSVG();
					var viewBoxtp=[0,0,boxWidth,boxheight];	
					control = new NCompass(pixel.x,pixel.y,60,height,{compassUrl:url+".svg"});
					this._addControl(control);
				},this);
			}else if(value == "text"){
				control = new NTextControl(x,y,90,24);
			}
			this._addControl(control);
		}
		this._currentTag=null;
	},
	_drawControl:function(e){
		if(this.currentEditTarget){
			this._refesh();
		}

		var target=e.currentTarget;
		var type=target.id; 
		
		var mapControl = this.getControlByType("NMapControl");
		var map = mapControl._printmap;
		
		target.style.border="4px dashed #DB4242";
		if(this._currentEle && this._currentEle.id!=type){
			this._currentEle.style.border="";
		}
		this._currentEle=target;
		if(this._currentGometryTag && this._currentGometryTag!="dragzoom"){
			map._handlers[this._currentGometryTag].disable();
		}
		
		var legendSel = document.getElementById("legendsSel");
		var value = legendSel.options[legendSel.options.selectedIndex].value;
		if(value != 'geometry'){
			this._currentTag = target.alt;
			map.on('click',this._drawFun,this);
		}else{
			var modeOptions = {  
				strokeColor: "red",   
				strokeWidth: 2,   
				strokeOpacity: 0.8,   
				fillColor: "yellow",   
				fillOpacity: 0.2,          
				editable: true  
			} 
			type = type.toLowerCase();
			this._currentGometryTag=type;
			switch(type)
			{
				case 'dragzoom':
				case 'drawpoint':
				case 'drawline':
				case 'drawpolygon':
				case 'drawrect':
					map.setMode(type);
				  break;
				case 'drawcurve':
					map._handlers[type]= new NMap.DrawCurve(map);
					map._handlers[type].enable();
				  break;  
				case 'drawfreeline':
					map._handlers[type]= new NMap.DrawFreeLine(map);
					map._handlers[type].enable();
				  break;  
				case 'drawarc':
					map._handlers[type]= new NMap.DrawArc(map);
					map._handlers[type].enable();
				  break;
				case 'drawroundedrect':
					map._handlers[type]= new NMap.DrawRoundedRect(map);
					map._handlers[type].enable();
				  break;  
				case 'drawcircles':
					map._handlers[type]= new NMap.DrawCircles(map);
					map._handlers[type].enable();
				  break;  
				case 'drawellipse':
					map._handlers[type]= new NMap.DrawEllipse(map);
					map._handlers[type].enable();
				  break;
				case 'drawlune':
					map._handlers[type]= new NMap.DrawLune(map);
					map._handlers[type].passpt = [];
					map._handlers[type].enable();
				  break;
				case 'drawsectorss':
					map._handlers[type]= new NMap.DrawSectorss(map);
					map._handlers[type].enable();
				  break;
				case 'drawclosedcurve':
					map._handlers[type]= new NMap.DrawClosedCurve(map);
					map._handlers[type].passpt = [];
					map._handlers[type].enable();
				  break;		
				case 'drawfreepolygon':
					map._handlers[type]= new NMap.DrawFreePolygon(map);
					map._handlers[type].enable();
				  break;
				case 'drawgatheringplace':
					map._handlers[type]= new NMap.DrawGatheringPlace(map);//NFineArrow
					map._handlers[type].enable();	
				  break;
				case 'drawstraightarrow':
					map._handlers[type]= new NMap.DrawStraightArrow(map);
					map._handlers[type].enable();	
				  break; 
				case 'drawpolylinearrow':
					map._handlers[type]= new NMap.DrawPolylineArrow(map);
					map._handlers[type].enable();	
				  break;   
				case 'drawfinearrow':
					map._handlers[type]= new NMap.DrawFineArrow(map);
					map._handlers[type].enable();	
				  break;    
				case 'drawassaultdirection':
					map._handlers[type]= new NMap.DrawAssaultDirection(map);
					map._handlers[type].enable();	
				  break;   
				case 'drawdoublearrow':
					map._handlers[type]= new NMap.DrawDoubleArrow(map);
					map._handlers[type].passpt = [];
					map._handlers[type].setHandlerOptions(modeOptions);
					map._handlers[type].enable();	
				  break;  
				case 'drawattackarrow':
					map._handlers[type]= new NMap.DrawAttackArrow(map);
					map._handlers[type].passpt = [];
					map._handlers[type].setHandlerOptions(modeOptions);
					map._handlers[type].enable();	
				  break;   
				case 'drawtailedattackarrow':
					map._handlers[type]= new NMap.DrawTailedAttackArrow(map);
					map._handlers[type].passpt = [];
					map._handlers[type].setHandlerOptions(modeOptions);
					map._handlers[type].enable();	
				  break;  
				case 'drawdiagonalarrow':
					map._handlers[type]= new NMap.DrawDiagonalArrow(map);
					map._handlers[type].passpt = [];
					map._handlers[type].setHandlerOptions(modeOptions);
					map._handlers[type].enable();	
				  break;  
				case 'drawdovetaildiagonalarrow':
					map._handlers[type]= new NMap.DrawDoveTailDiagonalArrow(map);
					map._handlers[type].passpt = [];
					map._handlers[type].setHandlerOptions(modeOptions);
					map._handlers[type].enable();	
				  break;
				case 'drawrectflag':
					map._handlers[type]= new NMap.DrawRectFlag(map);
					map._handlers[type].enable();
				  break;
				case 'drawtriangleflag':
					map._handlers[type]= new NMap.DrawTriangleFlag(map);
					map._handlers[type].enable();	
				  break;   
				case 'drawcurveflag':
					map._handlers[type]= new NMap.DrawCurveFlag(map);
					map._handlers[type].enable();	
				  break; 				  
				default:
				  return;
			}
		}
	},
	_btnModelIn: function(){
		var pane = document.getElementById('modelPane');
		pane.style.display="block";
		
	},
	_btnModelOut: function(){
		var pane = document.getElementById('modelPane');
		pane.style.display="none";
	},
	_selectModel: function(e){
		this._refesh();
		var target=	e.currentTarget;
		var templete = target.id;
		if(templete == ''){
			templete = "Template1";
		}
		this.options.templeteUrl=PRINT_JS_LIB.PRINT_URL+'/templet/'+templete+'.svg';
		this._mapPane.removeChild(this._pager._container);
		
		this._pager = null;
		this._pager = new NPager(this._mapPane);
		this._parseModel();
	},
	_paperSelectChange: function(e){
		var targetObj = e.currentTarget;
		var index = targetObj.selectedIndex; 
		var value = targetObj.options[index].value; 
		var obj = {"A0":{width:1180,height:841},"A1":{width:841,height:594},"A2":{width:594,height:420},"A3":{width:420,height:297},"A4":{width:297,height:210}};
		
		var widthtext = document.getElementById("widthtext");
		var heighttext = document.getElementById("heighttext");
		if(value == "自定义"){
			widthtext.disabled=false;
			heighttext.disabled= false;
		}else{
			widthtext.value=obj[value].width;
			heighttext.value=obj[value].height;
			widthtext.disabled=true;
			heighttext.disabled= true;
		}
	},
	_whtextChange: function(e){
		var scale = document.getElementById("widthHeightScale");
		if(scale.checked){
			var target = e.currentTarget;
			var paper = document.getElementById("_pager");
			var width = parseInt(paper.style.width);
			var height = parseInt(paper.style.height);
			
			if(target.id=="widthtext"){
				document.getElementById("heighttext").value = parseInt(target.value*(height/width));
			}else{
				document.getElementById("widthtext").value = parseInt(target.value*(width/height));
			}
		}
	},
	_legendsSelChange: function(e){
		var legendflotDiv = document.getElementById('legendflotDiv');
		if(legendflotDiv){
			legendflotDiv.style.display="none";
		}
		if(this._currentEle){
			this._currentEle.style.border="";
			this._currentEle=null;
		}
		if(this._currentGometryTag){
			var mapControl = this.getControlByType("NMapControl");
			var map = mapControl._printmap;
			if(this._currentGometryTag!="dragzoom"){
				map._handlers[this._currentGometryTag].disable();
			}
			
			this._currentGometryTag=null;
		}
		
		var legendSel = e.currentTarget;
		var value = legendSel.options[legendSel.options.selectedIndex].value;
		var divdl = document.getElementById("divdl");
		var dlArr = divdl.getElementsByTagName("dl");
		
		for(var i=0;i<dlArr.length;i++){
			var idArr = dlArr[i].id.split('_');
			if(idArr){
				if(idArr[2]==value && idArr[1]==0){
					dlArr[i].style.display="";
				}else{
					dlArr[i].style.display="none";
				}
			}
		}
		
		var dlArr2 = document.getElementsByName(value);
		var pageDiv = document.getElementById("pagebefafter");
		if(dlArr2.length<2){
			pageDiv.style.display="none";
		}else{
			pageDiv.style.display="";
			
			var pageafter = document.getElementById("pageafter");
			var pagebef = document.getElementById("pagebef");
			
			pagebef.src=PRINT_JS_LIB.PRINT_URL+'/images/geometry/pagebef.png';
			pageafter.src=PRINT_JS_LIB.PRINT_URL+'/images/geometry/pageafter.png';
		}
	},
	_legendMouseOver: function(e){
		var legendDiv = e.currentTarget;
		var legendflotDiv = document.getElementById("legendflotDiv");
		if(!legendflotDiv){
			legendflotDiv = NUtil.create('div');
			legendflotDiv.id="legendflotDiv";
			legendflotDiv.innerHTML='应用';
			NUtil.addClass(legendflotDiv, 'legendflot');
			var left_pane = document.getElementById("tc_left_pane");
			left_pane.appendChild(legendflotDiv);
			
			NEvent.addListener(legendflotDiv,'mouseover',this._legendflotMouseOver,this);
			NEvent.addListener(legendflotDiv,'mouseout',this._legendflotMouseOut,this);
			NEvent.addListener(legendflotDiv,'click',this._legendflotClick,this);
			NEvent.addListener(legendflotDiv,'blur',this._legendflotMouseOut,this);
		}
		legendflotDiv.style.left=legendDiv.offsetLeft+"px";
		legendflotDiv.style.top=legendDiv.offsetTop+legendDiv.clientWidth+10+"px";
		legendflotDiv.style.width=legendDiv.clientWidth+8+"px";

		legendflotDiv.style.display="";
		legendflotDiv.name=legendDiv.alt;
	},
	_legendMouseOut: function(e){
		var legendflotDiv = document.getElementById("legendflotDiv");
		if(legendflotDiv){
			var tmpElement = window.event.srcElement;
		}
	},
	_legendflotClick: function(e){
		var legendflotDiv = e.currentTarget;
		var url = legendflotDiv.name;
		var control;
		if(url){
			var legendSel = document.getElementById("legendsSel");
			var value = legendSel.options[legendSel.options.selectedIndex].value;
			if(value == "marker"){
				url +=".svg";
				Snap.load(url,function(f){ 
					var set =f.select("svg");	
					var width = parseFloat(set.attr('width'));
					var height = parseFloat(set.attr('height'));
					var viewBox = set.attr('viewBox');
					var boxWidth=width;
					var boxheight=height;
					if(viewBox){
						boxWidth = viewBox.width;
						boxheight = viewBox.height;
					}
					var scale = 35/width;
					height = scale*height;	
					var viewBoxtp=[0,0,boxWidth,boxheight];	
					control = new NSvgControl(0,0,35,height,{"svgNode":set.node,"viewBox":viewBoxtp,id:"marker"});
					this._addControl(control);
				},this);
			}else{
				if(value =="compass"){
					Snap.load(url+".svg",function(f){ 
						var set =f.select("svg");	
						var width = parseFloat(set.attr('width'));
						var height = parseFloat(set.attr('height'));
						var viewBox = set.attr('viewBox');
						var boxWidth=width;
						var boxheight=height;
						if(viewBox){
							boxWidth = viewBox.width;
							boxheight = viewBox.height;
						}
						var scale = 60/width;
						height = scale*height;	
						var svgHTML = set.innerSVG();
						var viewBoxtp=[0,0,boxWidth,boxheight];	
						control = new NCompass(0,0,60,height,{compassUrl:url+".svg"});
						this._addControl(control);
					},this);
				}else if(value == "text"){
					control = new NTextControl(5,5,90,24);
				}
				this._addControl(control);
			}
		}
	},
	_legendflotMouseOver: function(e){
		var legendflotDiv = e.currentTarget;
		if(legendflotDiv){
			legendflotDiv.style.display="";
		}
	},
	_legendflotMouseOut: function(e){
		var legendflotDiv = e.currentTarget;
		if(legendflotDiv){
			legendflotDiv.style.display="none";
		}
	},
	_btnCloseClick: function(e){
		var childrenNodes = this._container.children;
		for(var j=childrenNodes.length-1;j>=0;j--){
			this._container.removeChild(childrenNodes[j]);
		}
		this._container.innerHTML = '';
		this._container.style.display="none";
		//this._container._newmapPrint_used_tag = false;
		this.fire("printWindowClose",{id:this._container.id});	//暂时不需要分发事件*/
	},
	_btnSubmitClick: function(e){
		 var paper = document.getElementById("_pager");
		 var children = paper.children;
		
		 var svgstr='<svg width="'+parseFloat(paper.style.width)+'" height="'+parseFloat(paper.style.height)+'" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:inkpad="http://taptrix.com/inkpad/svg_extensions" xmlns:xlink="http://www.w3.org/1999/xlink" id="newSvgCrted">';
		 var mapDiv = document.getElementById('newmapMap');
		 var width = mapDiv.offsetWidth;
		 var height = mapDiv.offsetHeight;
		 var top = mapDiv.offsetTop;
		 var left = mapDiv.offsetLeft;
		 
		 var str = 'x="'+left+'" y="'+top+'" width="'+width+'" height="'+height+'"';
		 var mapControl = this.getControlByType("NMapControl");
		 var map = mapControl._printmap;
		 var bbox = map.getExtent();
		 var srsMapPro = map.getProjection();
		 var srsmap = '';
		 if(srsMapPro){
			srsmap = srsMapPro.srsCode;
		 }
		 str +=' minx="'+bbox.minX+'" miny="'+bbox.minY+'" maxx="'+bbox.maxX+'" maxy="'+bbox.maxY+'" srs="'+srsmap+'"';      
		 var mapstr = '<map '+str+'>\n';	
		
		 var layers = map.getLayers();
		 for(var n= 0; n < layers.length; n++){
			var layer = layers[n];
			var types = layer.getLayerType();
			if(types == 'NOverlayLayer'){
				continue;
			}
			var str2 = '';
			var url = layer.url;
			if(url.indexOf("?") == -1){
				url +='?';
			}
			if(types == "NMapServerLayer" || types == "NWMSLayer"){
				var srsPro = layer.getProjection();
				var srs = '';
				if(srsPro){
					srs = srsPro.srsCode;
				}
				var params = layer._params;
				var transparent = "false",format = "image/png",layresName = '';
				if(params && params.LAYERS){
					layresName = params.LAYERS;
				}	
				if(params && params.TRANSPARENT){
					transparent = params.TRANSPARENT;	
				}	
				if(layer.format){
					format = layer.format;	
				}
					
				if(types == "NMapServerLayer"){
					url +='LAYERS='+layresName+'&srsIn='+srs+'&srsOut='+srs+'&transparent='+transparent+'&where=&format='+format;
					str2= '<ms xlink:href="'+url+'"/>\n';
				}else{
					url +='LAYERS='+layresName+'&SRS='+srs+'&transparent='+transparent+'&format='+format;
					str2= '<wms xlink:href="'+url+'"/>\n';
				}
			}else if(types=="NWMTSLayer" || types=="NMultiLayer"){
				url +='LAYER='+layer.layer+'&format='+layer.format+'&style='+layer.style+'&TileMatrixSet='+layer.tileMatrixSet;
				str2= '<wmts xlink:href="'+url+'"/>\n';
			}
			mapstr += str2;
		 }
		 
		 var overLays = map._overlays;
		 var overStr1 = '',overStr2 = '',defstr = '';
		 for(var key in overLays){
			if(overLays.hasOwnProperty(key)){
				var overlay = map.getOverlay(key);
				if(overlay){
					var visible=true;
					var options = overlay.options;
					if(overlay.getVisible){
						visible = overlay.getVisible();
					}else{
						if(options.hasOwnProperty('visible')){
							visible = options.visible;
						}
					}
					if(!visible){
						continue;
					}
					var marker;
					
					if(overlay instanceof NMarker || overlay._type =="NPoint" || overlay._type =="NCircle" || overlay instanceof NLabel || overlay instanceof NRichMarker){
						var position = overlay.getPosition();
						//NMarker的背景图片 必须在 主Maker之前添加 不然会遮挡主marker图片
						if(overlay instanceof NMarker && options.shadowUrl !=''){
							overStr1 +='<point x="'+position.x+'" y="'+position.y+'" style="marker-start:url(#maker'+key+'_shadow);"/>\n';
						}
						
						overStr1 +='<point x="'+position.x+'" y="'+position.y+'" style="marker-start:url(#maker'+key+');"/>\n';
						
						//必须在 主Maker之后添加 不然字会被盖住
						if(overlay instanceof NRichMarker){
							overStr1 +='<point x="'+position.x+'" y="'+position.y+'" style="marker-start:url(#maker'+key+'_label);"/>\n';
						}
						
						if(overlay instanceof NMarker){
							var mAnchor = options.markerAnchor;
							var mSize = options.markerSize;
							var imageUrl=options.imgUrl;
							if(imageUrl.indexOf("http://")==-1){
								var url = document.location.toString();
								url = url.substring(0,url.lastIndexOf("/"));
								if(imageUrl.indexOf("../") !=-1){
									imageUrl = imageUrl.substring(imageUrl.indexOf("../")+3);
									url = url.substring(0,url.lastIndexOf("/"));
								}
								if(imageUrl.indexOf("./") !=-1){
									imageUrl = imageUrl.substring(imageUrl.indexOf("./")+2);
								}
								imageUrl = url+'/'+imageUrl;
							}
							var ix = -1;
							var iy = -1;
							if(overlay instanceof NSpriteMarker && options.imgOffset){
								ix= options.imgOffset.x;
								iy= options.imgOffset.y;
							}
							defstr +='<marker refX="'+mAnchor.x+'" refY="'+mAnchor.y+'" markerWidth="'+mSize.x+'" markerHeight="'+mSize.y+'" id="maker'+key+'">\n';
							defstr +='<image x="0" y="0" dx="'+ix+'" dy="'+iy+'" width="'+mSize.x+'" height="'+mSize.y+'" xlink:href="'+imageUrl+'"/>\n';	
							defstr +='</marker>\n';	
							
							if(options.shadowUrl && options.shadowUrl !=''){
								defstr +='<marker refX="'+options.shadowAnchor.x+'" refY="'+options.shadowAnchor.y+'" markerWidth="'+options.shadowSize.x+'" markerHeight="'+options.shadowSize.y+'" id="maker'+key+'_shadow">\n';
								defstr +='<image x="0" y="0" dx="'+ix+'" dy="'+iy+'" width="'+options.shadowSize.x+'" height="'+options.shadowSize.y+'" xlink:href="'+options.shadowUrl+'"/>\n';	
								defstr +='</marker>\n';	
							}
						}else if(overlay instanceof NRichMarker){
							var mAnchor = options.markerAnchor;
							var mSize = options.markerSize;
							var imageUrl = options.background;
							if(imageUrl.indexOf('(')!=-1){
								imageUrl = imageUrl.substring(imageUrl.indexOf('(')+1,imageUrl.indexOf(')'));
							}
							defstr +='<marker refX="'+mAnchor.x+'" refY="'+mAnchor.y+'" markerWidth="'+mSize.x+'" markerHeight="'+mSize.y+'" id="maker'+key+'">\n';
							defstr +='<image x="0" y="0" width="'+mSize.x+'" height="'+mSize.y+'" xlink:href="'+imageUrl+'"/>\n';	
							defstr +='</marker>\n';	

							var content = overlay._content;
							var labeloffset = options.labelAnchor;
							defstr +='<marker refX="-'+labeloffset.x+'" refY="-'+labeloffset.y+'" markerWidth="'+mSize.x+'" markerHeight="'+mSize.y+'" id="maker'+key+'_label">\n';
							defstr +='<text x="0" y="12" xml:space="preserve" style="baseline-shift:baseline;fill:#4d4d4d;fill-opacity:1;font-size:12;font-family:arial,simsun;stroke:#4d4d4d;stroke-width:0.2">'+content+'</text>\n';	
							defstr +='</marker>\n';							
						}
						else if(overlay instanceof NLabel){
							var width = overlay._element.clientWidth;
							var height = overlay._element.clientHeight;
							// var pixel = map.pointToPixel(position);
							// var xx = pixel.x+options.offset.x;
							// var yy = pixel.y+options.offset.y;
							// var point = map.pixelToPoint(new NXY(xx,yy));
							
							var content = options.content;//tspan
							var reg = /^\s*|\s*$/g;
							content = content.replace(reg, "");//去除前后空格
							if(content && content.indexOf('newmap_measure_dis')!=-1){
								var tmp1 = content.substring(6,content.indexOf('class')-6);
								var tmp2 = content.substring(content.indexOf('newmap_measure_dis')+20,content.indexOf('</span>'));
								var tmp3 = content.substring(content.indexOf('</span>')+7,content.lastIndexOf('</span>'));
								if(tmp1 == "总长："){
									content = tmp1+'<tspan style="fill:red;stroke:red;stroke-width:0.3">'+tmp2+'</tspan><tspan>'+tmp3+'</tspan>';
								}else{
									var str = tmp3.substring(0,tmp3.indexOf('<sup>'));
									var dxy = '';
									for(var j=0;j<str.length;j++){
										dxy +='0,';
									}
									content = tmp1+'<tspan style="fill:red;stroke:red;stroke-width:0.2">'+tmp2+'</tspan><tspan dx="'+dxy+'0" dy="'+dxy+'-5">'+str+'2</tspan>';
								}
							}
							var offset = options.offset;
				
							var style = options.style;
							var fontSize = '12';
							var color = "#000000";
							var fontFamily = "新宋体,arial,simsun";
							var backgroundColor = "#ffffe1";
							var rstrokeOpacity=1;
							if(style){
								fontSize=style.fontSize?style.fontSize:fontSize;
								color=style.color?style.color:color;	
								fontFamily=style.fontFamily?style.fontFamily:fontFamily;
								backgroundColor = style.backgroundColor?style.backgroundColor:backgroundColor;
								
								if(style.border=='none'){
									rstrokeOpacity=0;
								}
							}
							defstr +='<marker refX="-'+offset.x+'" refY="-'+offset.y+'" markerWidth="'+width+'" markerHeight="'+height+'" id="maker'+key+'">\n';
							defstr +='<rect  width="'+width+'" height="'+height+'" style="fill:'+backgroundColor+';stroke:#8c8c8c;stroke-width:1;stroke-opacity:'+rstrokeOpacity+';fill-opacity:1" />\n';
							defstr +='<text x="0" y="12" style="baseline-shift:baseline;fill:'+color+';fill-opacity:1;font-size:'+fontSize+';font-family:'+fontFamily+';stroke:'+color+';stroke-width:0">'+content+'</text>\n';	
							defstr +='</marker>\n';	
						}else{
							var r = overlay._radius;
							var cxy = r+options.strokeWidth;
							defstr +='<marker refX="'+cxy+'" refY="'+cxy+'" markerWidth="'+cxy*2+'" markerHeight="'+cxy*2+'" id="maker'+key+'">\n';
							defstr +='<circle cx="'+cxy+'" cy="'+cxy+'" r="'+r+'" style="fill:'+options.fillColor+';stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+';fill-opacity:'+options.fillOpacity+'"/>\n';	
							defstr +='</marker>\n';	
						}
					}else if(overlay instanceof NPolyline || overlay instanceof NPolygon || overlay instanceof NRect){
						var points=overlay.getPoints();
						if (overlay instanceof NSector) {
							overlay._lonlatFlag=true;
						}
						var ptstr = overlay._getPathPartStr(points);
						
						if(options.fill){
							overStr2 +='<path style="fill:'+options.fillColor+';stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+';fill-opacity:'+options.fillOpacity+'" d="'+ptstr+'"></path>';
						}
						else{
							overStr2 +='<path style="fill:none;stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+'" d="'+ptstr+'"></path>';
						}
						overStr2 +='\n';
					}else if(overlay instanceof NSector){
						var c = overlay._slatlng;
						var sp = overlay._passpoint;
						var r = c.distanceTo(sp);//map.getoverlay._radius;
						var ep = map.pixelToPoint(overlay._endpoint);
						ptstr = c.x + "," + c.y +" L" + sp.x + "," + sp.y +" A" + r + "," + r + ",0,0,0,"+ep.x  + "," + ep.y+" L" + c.x + "," + c.y+" z";

						overStr2 +='<path style="fill:'+options.fillColor+';stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+';fill-opacity:'+options.fillOpacity+'" d="M'+ptstr+'"></path>';
					}else if(overlay instanceof NMultiPoint){
						var points=overlay.getPoints();
						for(var n=0;n<points.length;n++){
							overStr1 +='<point x="'+points[n].x+'" y="'+points[n].y+'" style="marker-start:url(#maker'+key+'_'+n+');"/>\n';
						
							var r = overlay._radius;
							var cxy = r+options.strokeWidth;
							defstr +='<marker refX="'+cxy+'" refY="'+cxy+'" markerWidth="'+cxy*2+'" markerHeight="'+cxy*2+'" id="maker'+key+'_'+n+'">\n';
							defstr +='<circle cx="'+cxy+'" cy="'+cxy+'" r="'+r+'" style="fill:'+options.fillColor+';stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+';fill-opacity:'+options.fillOpacity+'"/>\n';	
							defstr +='</marker>\n';	
						}
					}
					else if(overlay instanceof NMultiPolyline ||  overlay instanceof NMultiPolygon){
						var points=overlay.getPoints();
						var ptstr='';
						for(var n=0;n<points.length;n++){
							ptstr +="M";
							for(var m=0;m<points[n].length;m++){
								ptstr +=points[n][m].x +" "+points[n][m].y+"L";
							}
							ptstr = ptstr.substring(0,ptstr.length-1);
							if(overlay instanceof NMultiPolygon){
								ptstr +='Z';
							}
						}
						if(overlay instanceof NMultiPolygon){
							overStr2 +='<path style="fill:'+options.fillColor+';stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+';fill-opacity:'+options.fillOpacity+'" d="'+ptstr+'"></path>';
						}
						else{
							overStr2 +='<path style="fill:none;stroke:'+options.strokeColor+';stroke-width:'+options.strokeWidth+';stroke-opacity:'+options.strokeOpacity+'" d="'+ptstr+'"></path>';
						}
						overStr2 +='\n';
					}
				}	
			}	
		 }		
		 mapstr += overStr2+overStr1;//path绘制时在前，marker在后
		 mapstr += '</map>\n';
		 svgstr +='\n'+ mapstr;
		 
		 var addstr = '';
		 for(var t=0;t<children.length;t++){
			 var eachElmt = children[t];
			 if(eachElmt.id == "newmapMap"){
				continue;
			 }	
			 
			 var viewBoxWid=0,viewBoxHei=0;
			 var eachSvg = eachElmt.children[0];
			 if(eachSvg.viewBox){
				 var viewBox = eachSvg.viewBox;
				 viewBoxWid = viewBox.animVal.width;
				 viewBoxHei = viewBox.animVal.height;
			 }
			 if(viewBoxWid==0 && eachSvg.viewport){
				 var viewport = eachSvg.viewport;
				 viewBoxWid = viewport.width;
				 viewBoxHei = viewport.height;
			 }
			 
			 if(viewBoxWid==0){
				 for(var q=0; q<eachSvg.attributes.length; q++){
					if(eachSvg.attributes[q].name=="viewBox"){
						var value = eachSvg.attributes[q].value;
						var arr;
						if(value.indexOf(',')!=-1){
							arr=value.split(',');
						}else{
							arr=value.split(' ');
						}
						if(arr.length>3){
							viewBoxWid=arr[2];viewBoxHei=arr[3];
						}
					}
				 }
			 }
			 var ws = parseFloat(eachElmt.style.width)/parseFloat(viewBoxWid);
			 var hs = parseFloat(eachElmt.style.height)/parseFloat(viewBoxHei);
			 
			 var svgTrfm=Snap("#"+eachSvg.id);
			  var str2 = svgTrfm.innerSVG();//svgTrfm.node.innerHTML;
			 var set = svgTrfm.selectAll('*');
			 var id = eachSvg.id;
			 id = id.substring(3,id.length);
			 
			 var arr=['defs','desc','g','style','metadata'];
			 var tmpm;
			 for(var s=0; s<set.length;s++){
				var element = set[s];
				var node = element.node;
				if(node.id=="line"+id){
					element.parent().remove();
					continue;
				}
				var falg=true;
				for(var m=0;m<arr.length;m++){
					if(element.type == arr[m]){
						falg=false;
						break;
					}
				}
				if(falg){
					var transform = element.transform();
					if(transform){
						var m = transform.localMatrix;
						tmpm = new Snap.Matrix(m.a,m.b,m.c,m.d,m.e,m.f);
						
						m.scale(ws,hs);
						var leftnum = 0,topnum=0;
						if(eachElmt.style.left){
							leftnum = parseFloat(eachElmt.style.left);
						}
						if(eachElmt.style.top){
							topnum = parseFloat(eachElmt.style.top);
						}
						var tmpm2 = new Snap.Matrix().translate(leftnum,topnum);
						m = new Snap.Matrix(m.a,m.b,m.c,m.d,tmpm2.e,tmpm2.f);
						element.transform(m);
					}
				}
			 }
			 var str = svgTrfm.innerSVG();//svgTrfm.node.innerHTML;
			 str = str.replace('xmlns=\"http://www.w3.org/2000/svg\"','');//only replace first one;
			 /**获取innerSVG之后 恢复要素的transform设置*/
			 var arr=['defs','desc','g','style','metadata'];
			 for(var s=0; s<set.length;s++){
				var element = set[s];
				var falg=true;
				for(var m=0;m<arr.length;m++){
					if(element.type == arr[m]){
						falg=false;
						break;
					}
				}
				if(falg){
					if(tmpm){
						element.transform(tmpm);
					}
				}
			 }
			 
			 if(str){
				var tmpss = str;
				if(str.indexOf('<desc>') !=-1){
					var str1 = str.substring(0,str.indexOf('<desc>'));
					var str2 = str.substring(str.indexOf('</desc>')+7,str.length);
					str = str1+str2;
					tmpss = str;
				}
				if(str.indexOf('<defs/>') !=-1){
					var str3 = str.substring(0,str.indexOf('<defs/>'));
					var str4 = str.substring(str.indexOf('<defs/>')+7,str.length);
					str = str3+str4;
					tmpss = str;
				}
				
				var tmp1='';
				 str = '\n'+str.substring(0,str.indexOf('>'));
				 var flag = false;
				 if(str.charAt(str.length-1)=="/"){
					str = str.substring(0,str.length-1);
					flag = true;
				 }else{
					tmp1 = tmpss.substring(tmpss.indexOf('>')+1,tmpss.length);
				 }
				 if(flag){
					str +=' />';
				 }else{
					str +='>';
					str += tmp1;
				 }
				 addstr +=str;	
			 }
		 } 
		 svgstr +=addstr+'\n'; 
		 svgstr +='<defs>\n'+defstr+'</defs>\n';
		 svgstr +='</svg>';
		
		var width = document.getElementById("widthtext").value;
		var height = document.getElementById("heighttext").value;
		
		var dpiSelect = document.getElementById("dpiSelect");
		var index = dpiSelect.selectedIndex; 
		var value = dpiSelect.options[index].value; 
		
		width = (parseFloat(width)/25.4*value).toFixed(0);
		height = (parseFloat(height)/25.4*value).toFixed(0);
		
		if(!width || !height){
			alert("请输入图片长宽！");
			return;
		}
		var formatSel = document.getElementById("formattext");
		var format = formatSel.options[formatSel.options.selectedIndex].value;
		
		var flag = false;
		var asynbtns = document.getElementsByName("asynradiobtn");
		for(var i=0;i<asynbtns.length;i++){
			if(asynbtns[i].checked==true){
				if(asynbtns[i].value=="yes"){
					flag= true;
				}
			}
		}
		
		var url = this.options.printServer+'?format=json&async='+flag;
		if(!flag){
			url+='&base64=true';
		}
		if(this.proxy){
			url = this.proxy + encodeURIComponent(url);
		}else{
			url = encodeURI(url);
		}
		//svgstr='<svg width=\"877.01\" height=\"620\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:inkpad=\"http://taptrix.com/inkpad/svg_extensions\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" id=\"newSvgCrted\">\n<map x=\"43\" y=\"60\" width=\"791\" height=\"491\" minx=\"63.8710653417118\" miny=\"3.4084773000000012\" maxx=\"144.66172534676474\" maxy=\"53.557926177978516\" srs=\"EPSG:4326\">\n<ms xlink:href=\"http://127.0.0.1:8099/newmap/rest/services/samples/china/MapServer/map?LAYERS=省级行政界面&srsIn=EPSG:4326&srsOut=EPSG:4326&transparent=false&where=&format=image/png\"/>\n</map>\n\n\n<g xmlns=\"http://www.w3.org/2000/svg\"  xmlns:NS1=\"\" NS1:inkpad:layername=\"White Outline\" >\n<path opacity=\"1\" fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"1.9\" transform=\"matrix(0.1172 0 0 0.1172 0 0)\" d=\"M 72.0007 431.908 C 73.6141 429.528 252.244 69.8115 252.244 69.8115 L 431.63 432.081 L 250.398 287.844 C 250.398 287.844 70.3874 434.288 72.0007 431.908 Z\" />\n<path opacity=\"1\" fill=\"#000000\" transform=\"matrix(0.1172 0 0 0.1172 0 0)\" d=\"M 250.376 287.849 C 252.251 289.323 431.63 432.137 431.63 432.137 L 252.217 69.8231 C 252.217 69.8231 248.501 286.374 250.376 287.849 Z\" />\n</g>\n\n<text font-size=\"30.0242\" font-weight=\"bold\" style=\"font-family: 宋体;\" fill=\"#000000\" fill-opacity=\"1\" stroke=\"#000000\" stroke-width=\"0\" transform=\"matrix(0.9999 0 0 1 355.57 7.15)\" x=\"0\" y=\"30.0242\">我的模版</text>\n<rect style=\"\" fill=\"none\" stroke=\"#000000\" stroke-width=\"2\" transform=\"matrix(1 0 0 1 34.82 50.02)\" x=\"0\" y=\"0\" width=\"808.988\" height=\"508.769\" border-style=\"undefined\" border-width=\"undefined\" />\n<rect style=\"\" fill=\"none\" stroke=\"#000000\" stroke-width=\"1\" transform=\"matrix(1 0 0 1 41.77 57.75)\" x=\"0\" y=\"0\" width=\"792.306\" height=\"494.227\" border-style=\"undefined\" border-width=\"undefined\" />\n<text font-size=\"20.0161\" style=\"font-family: 宋体;\" baseline-shift=\"baseline\" fill=\"#000000\" fill-opacity=\"0\" stroke=\"#000000\" stroke-width=\"1\" transform=\"matrix(1 0 0 0.9999 33.43 575.25)\" x=\"0\" y=\"20.0161\">制作单位:地理信息研究所</text>\n<text font-size=\"20.0161\" style=\"font-family: 宋体;\" baseline-shift=\"baseline\" fill=\"#000000\" fill-opacity=\"0\" stroke=\"#000000\" stroke-width=\"1\" transform=\"matrix(1 0 0 0.9999 283.63 575.25)\" x=\"0\" y=\"20.0161\">\n制作时间:2015/06/03</text>\n<defs>\n</defs>\n</svg>';
		var jsonObj={"layout":svgstr,"OUTFILE_FORMAT":format,"width":width,"height":height};
		var dtype = "";
		if (!flag) {
		    successFun = 1;
		} else {
		    dtype = "json";
		    successFun = 2;
		}
		this._addspinner();
		
		var t = this;
		$.ajax({
		    type: "POST",
		    url: url,
		    data: jsonObj,
		    dataType: dtype,
		    success: function (res) {
		        if (successFun == 1) {
		            t._removespinner();
		            var result = "data:image/png;base64," + res;
		            t.fire("printResult", { image: result, async: false });
		        } else {
		            //var data = eval('(' + res + ')');
		            var data = res;
		            if (data.error) {
		                alert(data.error);
		                return;
		            }
		            var status = data.STATUS;
		            t._statusId = data.RETURN_ID;
		            var _this = t;
		            t._interval = setInterval(function () {
		                var url = _this.options.printServer;
		                url = url.substring(0, url.indexOf("/services/utilities/") + 20);
		                url += "AsyncJob/AsyncServer/status?rid=" + _this._statusId + "&format=json";
		                if (_this.proxy) {
		                    url = _this.proxy + encodeURIComponent(url);
		                } else {
		                    url = encodeURI(url);
		                }

		                NRequest.GET({
		                    url: url,
		                    headers: _this.requestHeaders,
		                    success: _this._onStatusSuccess,
		                    failure: _this._onNaviFailure,
		                    scope: _this
		                });
		            }, 500);
		        }
		    },
		    error: t._onNaviFailure,
		});
	},
	_onNaviSuccess2:function(res){
		this._removespinner();
		var result = "data:image/png;base64,"+res.responseText;
		this.fire("printResult",{image:result,async:false});
	},
	_onNaviSuccess1:function(res){
		this._addspinner();
		var doc = res.responseText; 
		var data = eval('(' + doc + ')');
		if(data.error){
			alert(data.error);
			return;
		}
		var status = data.STATUS;
		this._statusId = data.RETURN_ID;
		var _this=this;
		this._interval = setInterval(function(){
			var url = _this.options.printServer;
			url=url.substring(0,url.indexOf("/services/utilities/")+20);
			url += "AsyncJob/AsyncServer/status?rid="+_this._statusId+"&format=json";
			if(_this.proxy){
				url = _this.proxy + encodeURIComponent(url);
			}else{
				url = encodeURI(url);
			}
			
			NRequest.GET({
				url: url,
				headers: _this.requestHeaders,
				success: _this._onStatusSuccess,
				failure: _this._onNaviFailure,
				scope: _this
			});
		},500);
	},
	_onStatusSuccess:function(res){
        var doc = res.responseText; 
		var data = eval('(' + doc + ')');
		if(data.STATUS=="SUCCEED" && data.PERCENT=="100"){
			this._removespinner();
			
			var url = this.options.printServer;
			url=url.substring(0,url.indexOf("/services/utilities/")+20);
			url+='AsyncJob/AsyncServer/result?rid='+this._statusId+'&format=png';
			this.fire("printResult",{image:url,async:true});
		}
    },	
	_onNaviFailure:function(request){
        if (this.failFunc != null) {
            this.failFunc(request);
        }
    },	
	_removespinner:function(){
		clearInterval(this._interval);
		this._spinner.spin();
		var target = document.getElementById('spinnerPane');
		target.style.display="none";
	},
	_addspinner:function(){
		var target = document.getElementById('spinnerPane');
		target.style.display="";
		var width=target.clientWidth;
		var height=target.clientHeight;
		 var opts = {            
            lines: 13, // 花瓣数目
            length: 20, // 花瓣长度
            width: 10, // 花瓣宽度
            radius: 30, // 花瓣距中心半径
            corners: 1, // 花瓣圆滑度 (0-1)
            rotate: 0, // 花瓣旋转角度
            direction: 1, // 花瓣旋转方向 1: 顺时针, -1: 逆时针
            color: '#000000', // 花瓣颜色
            speed: 1, // 花瓣旋转速度
            trail: 60, // 花瓣旋转时的拖影(百分比)
            shadow: false, // 花瓣是否显示阴影
            hwaccel: false, //spinner 是否启用硬件加速及高速旋转            
            className: 'spinner', // spinner css 样式名称
            zIndex: 2e9, // spinner的z轴 (默认是2000000000)
            top: height/2+'px', // spinner 相对父容器Top定位 单位 px
            left: width/2+'px'// spinner 相对父容器Left定位 单位 px
        };
        var spinner = new Spinner(opts);
		spinner.spin(target); 
		this._spinner=spinner;
	},
	_selectClick: function(e){
		var index = e.currentTarget.selectedIndex;
		var control;
		if(index == 1){
			control = new NCompass(40,50,60,60,{compassUrl:"compass.svg"});
		}else if(index == 2){
			control = new NTextControl(5,5,60,20);
		}
		if(control)
			this._addControl(control);
		e.currentTarget.selectedIndex = 0;
	},
	getControlByType: function(type){
		if(this._ctrlArr){
            for (var i in this._ctrlArr) {
                if (this._ctrlArr.hasOwnProperty(i) && this._ctrlArr[i]) {
                    if(this._ctrlArr[i].getType && (this._ctrlArr[i].getType().toLowerCase() == type.toLowerCase())){
                        return this._ctrlArr[i];
                    }
                }
            }
        }
        return false;		
	},
	_addControl: function(_ctrl){
		if(_ctrl){
			this._ctrlArr.push(_ctrl);
			_ctrl._setLayout(this);
		}
	},
	_removeControl: function(_ctrl){
		if(_ctrl){
			for (var i = 0; i < this._ctrlArr.length; i++) {
				if (this._ctrlArr[i] == _ctrl){
					this._ctrlArr.splice(i, 1);
					break;
				}
			}
			_ctrl._unsetLayout();
		}
	},
	_parseModel: function(){
		var _this = this;
		this._curCtrl = new Array(); 
		var mapPane = this._mapPane;
		var Pgrctner = this._pager;
		var oldmap = this._map;
		var inerSvg = document.createElementNS("http://www.w3.org/2000/svg","svg");
		Snap.load(this.options.templeteUrl,function(f){
			var set = f.selectAll("*");
			set.forEach(function(element,index){
			    switch(element.type){
					case "svg":
						var svgWidth = 0.0,svgHeight = 0.0,_viewBox='';
						for(var p=0;p<element.node.attributes.length;p++){
							var t=element.node.attributes[p];
							if(t.name=="viewBox"){_viewBox=t.value;}
							if(t.name=="width"){svgWidth = parseInt(t.value);continue;}
							if(t.name=="height"){svgHeight = parseInt(t.value);	continue;}
						}		 
						var tempW = parseFloat(Pgrctner._container.clientWidth);
						var tempH = parseFloat(Pgrctner._container.clientHeight);
						var scaleX = tempW/svgWidth; 
						var scaleY = tempH/svgHeight;
						if(scaleX>scaleY){
							height = svgHeight*scaleY;
							width = svgWidth*scaleY;
						}else{
							height = svgHeight*scaleX;
							width = svgWidth*scaleX;
						}
						
						Pgrctner._container.style.position ="absolute";
						Pgrctner._container.style.width = width+"px";
						Pgrctner._container.style.height = height+"px";
						Pgrctner._container.style.top = (parseFloat(mapPane.clientHeight)-height-40)/2 + 40 +"px";
						Pgrctner._container.style.left = (parseFloat(mapPane.clientWidth)-width)/2.0 + "px";
					
						inerSvg.setAttribute("id","nmsvg");
						inerSvg.setAttribute("width","100%");
						inerSvg.setAttribute("height","100%");
						inerSvg.setAttribute("viewBox","0,0,"+width+","+height);
						if(_viewBox){
							inerSvg.setAttribute("viewBox",_viewBox);
						}
						inerSvg.style.visibility = "hidden";
						break;
					case "map":					     
						var mapRect=document.createElementNS("http://www.w3.org/2000/svg","rect");
						for(var p=0;p<element.node.attributes.length;p++){
							var ele=element.node.attributes[p];
							mapRect.setAttribute(ele.name,ele.value);
						}
						mapRect.setAttribute("id","mapReplace");
						inerSvg.appendChild(mapRect);
						break;                     					 
					default :
						break;
			   } 
			});
			if(inerSvg)
			{
				Pgrctner._container.appendChild(inerSvg);
				var _svg = Snap("#nmsvg");
				_svg.add(set);
				var set = _svg.selectAll("*");
				set.forEach(function(element,index){
					var _ctrl = null;
					switch(element.type){
					    case "text":
							var transform = element.transform();
							var globalmatrix = transform.globalMatrix;
							var x=0, y=0,fontSize=0,_options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="x"){x=parseFloat(t.value);	continue;}
								 if(t.name=="y"){y=parseFloat(t.value);continue;}
								 if(t.name=="font-size"){fontSize=parseFloat(t.value);continue;}
								 _options[t.name]=t.value;
							}
							var bbox = element.getBBox();
							
							var m = new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(x,y-fontSize);
							if(_options["stroke-width"]==''||_options["stroke-width"]==undefined){
								m.scale(bbox.width,bbox.height);
							}else{
								m.scale(bbox.width+parseFloat(_options["stroke-width"]),bbox.height+parseFloat(_options["stroke-width"]));
							}	 
							var n = new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							n.scale(fontSize,fontSize);
													 
							var _elmt = document.createElementNS("http://www.w3.org/2000/svg","text"); 
							 _elmt.textContent = element.node.textContent;
							 _elmt.setAttribute("font-size",n.a);
							 _elmt.setAttribute("x","0");
							 _elmt.setAttribute("y",n.a);
							for(var key in _options){
								if(_options.hasOwnProperty(key)){
									if(key !=='xmlns' && key !=='transform' && key !=='xml:space'){
										_elmt.setAttribute(key,_options[key]);
									}
								}
							}
							var viewBox = [0,0,m.a+n.a/5,m.d+n.a/5];
							_ctrl = new NSvgControl(m.e,m.f,m.a+n.a/5,m.d+n.a/5,{"svgText":_elmt,"viewBox":viewBox,id:"text"});
						    break;
					    case "rect":						
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var x=0, y=0,fontSize=0,_options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="x"){x=parseFloat(t.value);	continue;}
								 if(t.name=="y"){y=parseFloat(t.value);continue;}
								 _options[t.name]=t.value;
							}
							var bbox = element.getBBox();
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(x,y);
							m.scale(_options["width"],_options["height"]);
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","rect"); 
							 if(_options["fill"]==""){
								 _elmt.setAttribute("fill","none");
							 }else{	 
								_elmt.setAttribute("fill", _options["fill"]);
							 }
							 _elmt.setAttribute("stroke", _options["stroke"]);
							 _elmt.setAttribute("style",_options['style']);
							 _elmt.setAttribute("border-style", _options['border-style']);
							 _elmt.setAttribute("border-width", _options['border-width']);
							 _elmt.setAttribute("stroke-width", _options['stroke-width']);
							 _elmt.setAttribute("width",m.a);
							 _elmt.setAttribute("height",m.d);
							 _elmt.setAttribute("x","0");
							 _elmt.setAttribute("y","0");	
							 
							if(element.node.id=="mapReplace"){							  
								 _ctrl = new NMapControl(m.e,m.f,m.a,m.d,oldmap);
							}else{					 
								var svgText =_elmt.outerHTML;
								var viewBox = [0,0,m.a,m.d];
								_ctrl = new NSvgControl(m.e,m.f,m.a,m.d,{"svgText":_elmt,"viewBox":viewBox});
							 }
						    break;
						case "circle":
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var x=0, y=0,_options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="cx"){x=parseFloat(t.value);	continue;}
								 if(t.name=="cy"){y=parseFloat(t.value);continue;}
								 if(t.name=="r"){_options["r"]=parseFloat(t.value);continue;}
								 _options[t.name]=t.value;
							} 
							
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(x,y);
							if(_options["stroke-width"]==''||_options["stroke-width"]==undefined){
								m.scale(2*_options["r"],2*_options["r"]);
							}else{
								m.scale(2*_options["r"]+parseFloat(_options["stroke-width"]),2*_options["r"]+parseFloat(_options["stroke-width"]));
							}						
							
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","circle"); 
							if(_options["fill"]==""){ 
								 _elmt.setAttribute("fill","none");
							 }else{ _elmt.setAttribute("fill", _options["fill"]);}
							 _elmt.setAttribute("stroke", _options["stroke"]);
							 _elmt.setAttribute("border-style", _options['border-style']);
							 _elmt.setAttribute("border-width", _options['border-width']);
							 _elmt.setAttribute("style",_options['style']); 
							 _elmt.setAttribute("stroke-width", _options['stroke-width']);
							 _elmt.setAttribute("r",(m.a)/2);	
							 _elmt.setAttribute("cx",m.a/2.0);				 
							 _elmt.setAttribute("cy",m.d/2.0);
							 
							var svgText =_elmt.outerHTML;
							var viewBox = [0,0,m.a,m.d];
							_ctrl = new NSvgControl(m.e-(m.a)/2,m.f-(m.d)/2,m.a,m.d,{"svgText":svgText,"viewBox":viewBox});
						    break;
					    case "ellipse":
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var x=0, y=0,_options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="cx"){x=parseFloat(t.value);	continue;}
								 if(t.name=="cy"){y=parseFloat(t.value);continue;}
								 if(t.name=="rx"){_options["rx"]=parseFloat(t.value);continue;}
								 if(t.name=="ry"){_options["ry"]=parseFloat(t.value);continue;}
								 _options[t.name]=t.value;
							} 
							
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(x,y);
							if(_options["stroke-width"]==''||_options["stroke-width"]==undefined){
								m.scale(2*_options["rx"],2*_options["ry"]);
							}else{
								m.scale(2*_options["rx"]+parseFloat(_options["stroke-width"]),2*_options["ry"]+parseFloat(_options["stroke-width"]));
							}
							
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","ellipse"); 
							if(_options["fill"]==""){ 
								 _elmt.setAttribute("fill","none");
							 }else{ _elmt.setAttribute("fill", _options["fill"]);}
							 _elmt.setAttribute("stroke", _options["stroke"]);
							 _elmt.setAttribute("border-style", _options['border-style']);
							 _elmt.setAttribute("border-width", _options['border-width']);
							 _elmt.setAttribute("style",_options['style']); 
							 _elmt.setAttribute("stroke-width", _options['stroke-width']);
							 _elmt.setAttribute("rx",m.a/2.0);
							 _elmt.setAttribute("ry",m.d/2.0);						 
							 _elmt.setAttribute("cx",m.a/2.0);				 
							 _elmt.setAttribute("cy",m.d/2.0);
							 
							var svgText =_elmt.outerHTML;
							var viewBox = [0,0,m.a,m.d];
							_ctrl = new NSvgControl(m.e-(m.a)/2,m.f-(m.d)/2,m.a,m.d,{"svgText":svgText,"viewBox":viewBox});
						    break;
					    case "line":
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var x1=0, y1=0,x2=0, y2=0,_options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="x1"){x1=parseFloat(t.value);	continue;}
								 if(t.name=="y1"){y1=parseFloat(t.value);continue;}
								 if(t.name=="x2"){x2=parseFloat(t.value);continue;}
								 if(t.name=="y2"){y2=parseFloat(t.value);continue;}
								 _options[t.name]=t.value;
							} 
							
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(x1,y1);
							m.scale(x2-x1,y2-y1);
							
							var n=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							n.translate(x2,y2);
							 
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","line"); 
							if(_options["fill"]==""){
								_elmt.setAttribute("fill","none");
							}else{
								_elmt.setAttribute("fill", _options["fill"]);
							}
							 _elmt.setAttribute("stroke-width", _options['stroke-width']);
							 _elmt.setAttribute("stroke", _options["stroke"]);
							 _elmt.setAttribute("border-style", _options['border-style']);
							 _elmt.setAttribute("border-width", _options['border-width']);
							 _elmt.setAttribute("x1","0");
							 _elmt.setAttribute("y1","0");
							 _elmt.setAttribute("x2",m.a);
							 _elmt.setAttribute("y2",m.d);
							 _elmt.setAttribute("style",_options['style']);
							 
							var svgText =_elmt.outerHTML;
							var viewBox = [0,0,m.a,m.d];
							_ctrl = new NSvgControl(m.e,m.f,m.a,m.d,{"svgText":svgText,"viewBox":viewBox});
						    break;					   
					    case "polygon":
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var _options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="points"){_options['points']=t.value;	continue;}							 
								 _options[t.name]=t.value;
							} 
							
							var bbox = element.getBBox();
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(bbox.x,bbox.y);
							
							if(_options["stroke-width"]==''||_options["stroke-width"]==undefined){
								m.scale(bbox.width,bbox.height);
							}else{
								m.scale(bbox.width+parseFloat(_options["stroke-width"]),bbox.height+parseFloat(_options["stroke-width"]));
							}
							
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","polygon"); 
							if(_options["fill"]==""){
								_elmt.setAttribute("fill","none");
							}else{
								_elmt.setAttribute("fill", _options["fill"]);
							}
							_elmt.setAttribute("stroke-width", _options['stroke-width']);
							_elmt.setAttribute("stroke", _options["stroke"]);
							_elmt.setAttribute("border-style", _options['border-style']);
							_elmt.setAttribute("border-width", _options['border-width']);
							
							var _points='' ,small_X=0,small_Y=0;
							var arr_points=_options['points'].split(' ');
							for(var q=0;q<arr_points.length;q++){
								var brr=arr_points[q].split(',');
								var n=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
								globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
								n.translate(brr[0],brr[1]);		
								 if(q!=0){
									_points+=' '; 
								 }								
								_points+=n.e+','+n.f;
							}
							
							var sm_points=_points.split(' ');
							for(var sm=0;sm<sm_points.length;sm++){
								if(sm_points[sm]!=''){
								var amArr=sm_points[sm].split(',');
								if(sm==0){small_X=amArr[0];small_Y=amArr[1];}
								if(parseFloat(small_X)>parseFloat(amArr[0])){
									small_X=amArr[0];}
								if(parseFloat(small_Y)>parseFloat(amArr[1])){
									small_Y=amArr[1];}
								}
							}
							
							_options['points']=_this.parsePL(_points,small_X,small_Y);
							_elmt.setAttribute("points",_options['points']);
							_elmt.setAttribute("style",_options['style']);
							 
							var svgText =_elmt.outerHTML;
							var viewBox = [0,0,m.a,m.d];
							_ctrl = new NSvgControl(m.e,m.f,m.a,m.d,{"svgText":svgText,"viewBox":viewBox});
						    break;
					    case "polyline":
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var _options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="points"){_options['points']=t.value;	continue;}							 
								 _options[t.name]=t.value;
							} 
							
							var bbox = element.getBBox();
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(bbox.x,bbox.y);
							if(_options["stroke-width"]==''||_options["stroke-width"]==undefined){
								m.scale(bbox.width,bbox.height);
							}else{
								m.scale(bbox.width+parseFloat(_options["stroke-width"]),bbox.height+parseFloat(_options["stroke-width"]));
							}
							
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","polyline"); 
							if(_options["fill"]==""){
							 _elmt.setAttribute("fill","none");
							}else{_elmt.setAttribute("fill", _options["fill"]);}
							 _elmt.setAttribute("stroke-width", _options['stroke-width']);
							 _elmt.setAttribute("stroke", _options["stroke"]);
							 _elmt.setAttribute("border-style", _options['border-style']);
							 _elmt.setAttribute("border-width", _options['border-width']);
							
							var _points='' ,small_X=0,small_Y=0;
							var arr_points=_options['points'].split(' ');
							for(var q=0;q<arr_points.length;q++){
								var brr=arr_points[q].split(',');
								var n=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
								globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
								n.translate(brr[0],brr[1]);	
								 if(q!=0){
									_points+=' '; 
								 }							
								_points+=n.e+','+n.f;
							}
							
							var sm_points=_points.split(' ');
							for(var sm=0;sm<sm_points.length;sm++){
								if(sm_points[sm]!=''){
								var amArr=sm_points[sm].split(',');
								if(sm==0){small_X=amArr[0];small_Y=amArr[1];}
								if(parseFloat(small_X)>parseFloat(amArr[0])){
									small_X=amArr[0];}
								if(parseFloat(small_Y)>parseFloat(amArr[1])){
									small_Y=amArr[1];}
								}
							}
							
							_options['points']=_this.parsePL(_points,small_X,small_Y);
							_elmt.setAttribute("points",_options['points']);
							_elmt.setAttribute("style",_options['style']);
							 
							var svgText =_elmt.outerHTML;
							var viewBox = [0,0,m.a,m.d];
							_ctrl = new NSvgControl(m.e,m.f,m.a,m.d,{"svgText":svgText,"viewBox":viewBox});
						    break;
					    case "path":
							var t = element.transform();
							var globalmatrix = t.globalMatrix;
							var _options=new Object();
							for(var p=0;p<element.node.attributes.length;p++){
								 var t=element.node.attributes[p];
								 if(t.name=="d"){_options['d']=t.value;	continue;}							 
								 _options[t.name]=t.value;
							} 
							
							var bbox = element.getBBox();
							var m=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
							globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
							m.translate(bbox.x,bbox.y);
							if(_options["stroke-width"]==''||_options["stroke-width"]==undefined){
								m.scale(bbox.width,bbox.height);
							}else{
								m.scale(bbox.width+parseFloat(_options["stroke-width"]),bbox.height+parseFloat(_options["stroke-width"]));
							}
							
							var _elmt=document.createElementNS("http://www.w3.org/2000/svg","path"); 
							if(_options["fill"]==""){
								_elmt.setAttribute("fill","none");
							 }else{
								_elmt.setAttribute("fill", _options["fill"]);
							}
							 _elmt.setAttribute("stroke-width", _options['stroke-width']);
							 _elmt.setAttribute("stroke", _options["stroke"]);
							 _elmt.setAttribute("border-style", _options['border-style']);
							 _elmt.setAttribute("border-width", _options['border-width']);					
							 
							var allPath=_options['d'].split(' ');
							var pathData='',small_X=0,small_Y=0;
							for(var r=0;r<allPath.length;r++){
								var onePoint=allPath[r].split(',');
								if(r!=0){pathData+=' ';}							
								var n=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
										globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
								if(onePoint.length==0||onePoint[0]==''){continue;}
								var letter=onePoint[0].match(/[a-zA-Z]/g)[0];
								var num=parseFloat(onePoint[0].split(letter)[1]);							
								switch(letter){
									case "M":								    
										n.translate(num,onePoint[1]);
										pathData+=letter+n.e+','+n.f;								     
										break;
									case "L":								   
										n.translate(num,onePoint[1]);
										pathData+=letter+n.e+','+n.f;	
										break;
									case "H":								     
										n.translate(num,0);
										pathData+=letter+n.e+','+n.f;
										break;
									case "V":								    
										n.translate(0,num);
										pathData+=letter+n.e+','+n.f;
										break;
									case "C":								    
										 n.translate(num,onePoint[1]);
										 pathData+=letter+n.e+','+n.f;
										for(var e=2;e<onePoint.length;e++){										
											pathData+=',';
											var n=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
											globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
											n.translate(onePoint[e],onePoint[e+1]);
											pathData+=n.e+','+n.f;
											e++;
										}
										break;
									case "S":
										
										break;
									case "Q":
										break;
									case "T":								   
										n.translate(num,onePoint[1]);
										pathData+=letter+n.e+','+n.f;	
										break;
									case "A":
									
										break;
									case "Z":
										 pathData+="Z";
										break;	
									default :
										break;
								}
							} 
							
							var _allPath=pathData.split(' ');
							for(var p=0;p<_allPath.length;p++){
								var _onePoint=_allPath[p].split(',');
								if(p!=0){pathData+=' ';}							
								var n=new Snap.Matrix(globalmatrix.a,globalmatrix.b,
										globalmatrix.c,globalmatrix.d,globalmatrix.e,globalmatrix.f);
								if(_onePoint.length==0||_onePoint[0]==''){continue;}
								var _letter=_onePoint[0].match(/[a-zA-Z]/g)[0];
								var _num=parseFloat(_onePoint[0].split(_letter)[1]);							
								switch(_letter){
									case "M":
										small_X=_num;
										small_Y=parseFloat(_onePoint[1]);
										break;
									case "L":
										if(parseFloat(small_X)>_num){small_X=_num;}
										if(parseFloat(small_Y)>parseFloat(_onePoint[1])){small_Y=_onePoint[1];}								   
										break;
									case "H":
										if(parseFloat(small_X)>_num){small_X=_num;}								   
										break;
									case "V":
										if(parseFloat(small_Y)>_num){small_Y=_num;}								   
										break;
									case "C":
										if(parseFloat(small_X>_num)){small_X=_num;}
										if(parseFloat(small_Y)>parseFloat(_onePoint[1])){small_Y=_onePoint[1];}
										for(var e=2;e<_onePoint.length;e++){
											if(parseFloat(small_X)>parseFloat(_onePoint[e])){small_X=_onePoint[e];}
											if(parseFloat(small_Y)>parseFloat(_onePoint[e+1]))
											{small_Y=_onePoint[e+1];}										
											e++;
										}
										break;
									case "S":
										
										break;
									case "Q":
										break;
									case "T":
										if(parseFloat(small_X)>_num){small_X=_num;}
										if(parseFloat(small_Y)>parseFloat(_onePoint[1])){small_Y=_onePoint[1];}
										break;
									case "A":
										break;
									case "Z":
										break;	
									default :
										break;
								}
							} 
												
							 _options['d']=_this._parsePath(pathData,small_X,small_Y);
							 _elmt.setAttribute("d",_options['d']);					 
							 _elmt.setAttribute("style",_options['style']);
													 
							var svgText =_elmt.outerHTML;
							var viewBox = [0,0,m.a,m.d];
							_ctrl = new NSvgControl(m.e,m.f,m.a,m.d,{"svgText":svgText,"viewBox":viewBox});
						    break;
						default :
							break;
					} 
					if(_ctrl){
						_this._addControl(_ctrl);
					}
				});
				Pgrctner._container.removeChild(inerSvg);
				Pgrctner._container.style.visibility ="visible";				
			}
			
			 var widthtext = document.getElementById("widthtext");
			 var heighttext = document.getElementById("heighttext");
			 if(widthtext){
				 widthtext.value = (parseInt(Pgrctner._container.style.width)/96*25.4).toFixed(0);
			 }
			 if(heighttext){
				 heighttext.value = (parseInt(Pgrctner._container.style.height)/96*25.4).toFixed(0);
			 }
		});	
	},
	parsePL: function(coordStr,x,y){
		var _x=x,
		    _y=y;
		var dataStr='';
		if(coordStr){			
			var pointsArr=coordStr.split(' ');
			for(var q=0;q<pointsArr.length;q++){
				 var twoNum=pointsArr[q].split(',');
				 dataStr+=(twoNum[0]-_x)+","+(twoNum[1]-_y)+" ";
			}
		}
		return dataStr;	
	},
	_parsePath: function(coordStr,x,y){
		var _x=x,
		    _y=y;
		var dataStr='';
		if(coordStr){			
			var pointsArr=coordStr.split(' ');
			for(var q=0;q<pointsArr.length;q++){
                var manyPoints=pointsArr[q].split(',');
				if(manyPoints.length==0||manyPoints[0]==''){continue;}
				var firLetter=manyPoints[0].match(/[a-zA-Z]/g)[0]; 
				var firNum=parseFloat(manyPoints[0].split(firLetter)[1]);//带字母的数字				
				if(q!=0){dataStr+=' ';}
				switch(firLetter){
					case "M":
					     dataStr+=firLetter+(firNum-_x)+','+(manyPoints[1]-_y);
					break;
					case "L":
					      dataStr+=firLetter+(firNum-_x)+','+(manyPoints[1]-_y);
					break;
					case "H":
					break;
					case "V":
					break;
					case "C":
					      dataStr+=firLetter+(firNum-_x)+','+(manyPoints[1]-_y);
						  for(var t=2;t<manyPoints.length;t++){
							 dataStr+=',';
							 dataStr+=(manyPoints[t]-_x)+','+(manyPoints[t+1]-_y);
							 t++;
						  }
						  
					break;
					case "S":
					     
					break;
					case "Q":
					break;
					case "T":
					     dataStr+=firLetter+(firNum-_x)+','+(manyPoints[1]-_y);
					break;
					case "A":
					break;
					case "Z":
					break;	
					default :
					break;
				}
			}
		}
		return dataStr;	
	},	
	_printSvg: function(){
	    var allDiv=this._pager._container.getElementsByTagName("div");
		var alldivWithoutMap=[];
		for(var p=0;p<allDiv.length;p++){
			if(allDiv[p].className==''){alldivWithoutMap.push(allDiv[p]);}
		}
		 var svg= document.createElementNS("http://www.w3.org/2000/svg","svg");		  
		 svg.setAttribute("width", parseFloat(this._pager._container.style.width));
		 svg.setAttribute("height", parseFloat(this._pager._container.style.height));
		 svg.setAttribute("version","1.1");
		 svg.setAttribute("xmlns","http://www.w3.org/2000/svg");
		 svg.setAttribute("xmlns:inkpad","http://taptrix.com/inkpad/svg_extensions");
		 svg.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");
		 svg.setAttribute("id","newSvgCrted");		 
		 
		 for(var t=0;t<alldivWithoutMap.length;t++){
			 var eachElmt=alldivWithoutMap[t];
			 var m = new Snap.Matrix();
				 var viewBoxWid=0,viewBoxHei=0;
				 var eachSvg=alldivWithoutMap[t].childNodes[0];
				 var svgTrfm=Snap("#"+eachSvg.id);
				 for(var q=0;q<eachSvg.attributes.length;q++){
					 if(eachSvg.attributes[q].name=="viewBox"){
						 var arr=eachSvg.attributes[q].value.split(',');
						 viewBoxWid=arr[2];viewBoxHei=arr[3];
					 }
				 }
				 
				 m.scale(parseFloat(eachElmt.style.width)/parseFloat(viewBoxWid),parseFloat(eachElmt.style.height)/parseFloat(viewBoxHei));
				 svgTrfm.select(svgTrfm.node.childNodes[0].nodeName).transform(m);
				 svg.innerHTML+=svgTrfm.node.innerHTML;
		 }
		 return svg.outerHTML;
    },
	setModel: function(options){
		var pager=document.getElementById("_pager");
	    if(pager){  pager.innerHTML="";  }
	    if(options==undefined){
			this.options.templeteUrl="moRen.svg";
		}else{
			this._options=options;
			if(options.templeteUrl==""){this.options.templeteUrl="moRen.svg";}
		}
		this._parseModel();
   }
});












